脚本中Groovy和Powershell变量的混合-Jenkins

时间:2019-12-04 14:10:11

标签: powershell jenkins-pipeline

我正在努力让他们在詹金斯管道中工作:

stage('Initiate Build Variables') {
            steps {
                withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '27f6313e-1d43-4552-8869-adea55dacce2', usernameVariable: 'ELEVATED_USER', passwordVariable: 'ELEVATED_PASSWORD']]) {
                powershell label: '', returnStdout: true, script: """
                \$secpasswd = ConvertTo-SecureString "${ELEVATED_PASSWORD}" -AsPlainText -Force
                Write-output \$secpasswd
                Write-output "date"
                \$mycreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @(${ELEVATED_USER},\$secpasswd)
                Write-Output \$mycreds
                """
                }
                }
        } 

我最终在管道的输出中得到以下信息:

Masking supported pattern matches of %ELEVATED_USER% or %ELEVATED_PASSWORD%
[Pipeline] {
[Pipeline] powershell (hide)
 > git branch -a -v --no-abbrev # timeout=10
 > git checkout -b master ea91b828649ae51629db78b7ada9b490ff682084
At E:\Jenkins\workspace\onprem-2012@tmp\durable-abb32110\powershellScript.ps1:5 char:117
+ ... anagement.Automation.PSCredential -ArgumentList @(****,$secpass ...
+                                                                 ~
Missing argument in parameter list.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingArgument


[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }

感觉好像没有正确传递$ secpasswd变量来创建伪对象,但是我有点茫然,因为我不确定groovy变量和运行时定义的powershell变量的混合语法是否正确

1 个答案:

答案 0 :(得分:2)

语法对我来说不错,除了:

.navbar .navbar-brand,.hestia-about p {
    font-size: 18px
}
body {
    font-size: 14px
}
.navbar,.navbar a {
    font-size: 12px
}
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-weight: 300;
    line-height: 1.618
}
ul {
    line-height: 1.618
}
h2,h4 {
    font-weight: 500;
    line-height: 1.618
}
button {
    font-size: 12px;
    font-weight: 400
}
button {
    font-size: inherit;
    line-height: inherit
}
.navbar .navbar-brand {
    line-height: 30px
}
.navbar .navbar-nav>li>a {
    font-weight: 400
}
.navbar .dropdown-menu li>a {
    font-size: 13px
}
.hestia-about {
    font-weight: 300
}
.hestia-about h2,.hestia-about h4 {
    font-weight: 700
}
@media (max-width:768px) {
    .navbar .navbar-nav li .caret {
        font-size: 20px
}
    .navbar .navbar-nav .dropdown .dropdown-menu li a {
        line-height: 20px
}
}
body {
    direction: ltr;
    color: #3c4858;
    font-family: "Roboto", "Helvetica", "Arial", sans-serif
}
h2,h4 {
    font-family: "Roboto", "Helvetica", "Arial", sans-serif
}
a {
    color: #9c27b0
}
.container {
    max-width: 100%
}
@media (min-width:749px) {
    .container {
        max-width: 748px
}
}
@media (min-width:768px) {
    .container {
        max-width: 750px
}
}
@media (min-width:992px) {
    .container {
        max-width: 970px
}
}
@media (min-width:1200px) {
    .container {
        max-width: 2000px
}
}
body {
    direction: ltr;
    background-color: #e5e5e5;
    overflow-x: hidden
}
img,button {
    max-width: 100%
}
img {
    height: auto
}
ul {
    margin-bottom: 30px
}
.container {
    max-width: 100%
}
:focus,:active,::-moz-focus-inner {
    outline: 0!important
}
button {
    border: 0
}
button {
    font-family: inherit;
    padding: 7px
}
button {
    position: relative;
    margin: 10px 1px;
    padding: 12px 30px;
    border: none;
    border-radius: 3px;
    white-space: normal;
    letter-spacing: 0;
    text-transform: uppercase
}
button {
    -webkit-box-shadow: 0 2px 2px 0 rgba(153, 153, 153, .14), 0 3px 1px -2px rgba(153, 153, 153, .2), 0 1px 5px 0 rgba(153, 153, 153, .12);
    -moz-box-shadow: 0 2px 2px 0 rgba(153, 153, 153, .14), 0 3px 1px -2px rgba(153, 153, 153, .2), 0 1px 5px 0 rgba(153, 153, 153, .12);
    box-shadow: 0 2px 2px 0 rgba(153, 153, 153, .14), 0 3px 1px -2px rgba(153, 153, 153, .2), 0 1px 5px 0 rgba(153, 153, 153, .12)
}
button {
    -webkit-box-shadow: 0 2px 2px 0 rgba(156, 39, 176, .14), 0 3px 1px -2px rgba(156, 39, 176, .2), 0 1px 5px 0 rgba(156, 39, 176, .12);
    -moz-box-shadow: 0 2px 2px 0 rgba(156, 39, 176, .14), 0 3px 1px -2px rgba(156, 39, 176, .2), 0 1px 5px 0 rgba(156, 39, 176, .12);
    box-shadow: 0 2px 2px 0 rgba(156, 39, 176, .14), 0 3px 1px -2px rgba(156, 39, 176, .2), 0 1px 5px 0 rgba(156, 39, 176, .12)
}
button {
    color: #fff;
    background-color: #9c27b0
}
.navbar button.navbar-toggle {
    color: #555
}
.navbar {
    background-color: #fff;
    color: #555;
    border-radius: 0;
    position: fixed;
    border: none;
    padding: 0;
    -webkit-box-shadow: 0 1px 10px -6px rgba(0, 0, 0, .42), 0 1px 10px 0 rgba(0, 0, 0, .12), 0 4px 5px -2px rgba(0, 0, 0, .1);
    box-shadow: 0 1px 10px -6px rgba(0, 0, 0, .42), 0 1px 10px 0 rgba(0, 0, 0, .12), 0 4px 5px -2px rgba(0, 0, 0, .1)
}
.navbar .navbar-collapse {
    border: none
}
.navbar .title-logo-wrapper {
    max-width: 250px;
    display: flex;
    align-items: center
}
.navbar>.container {
    display: flex;
    padding: 10px 15px;
    vertical-align: middle;
    align-items: center
}
.navbar.hestia_left .navbar-collapse {
    margin-left: auto
}
.navbar.hestia_left>.container {
    flex-direction: row
}
.navbar.hestia_left .navbar-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end
}
.navbar .navbar-header .navbar-brand {
    padding: 0 15px;
    position: relative;
    color: inherit;
    height: auto
}
.navbar .navbar-header .navbar-brand img {
    width: auto;
    max-height: 50px
}
.navbar-toggle-wrapper {
    margin-left: auto;
    display: flex;
    align-items: center;
    flex-direction: row
}
.navbar .navbar-toggle {
    float: none;
    border: 0;
    margin-right: 0
}
.navbar .navbar-toggle .icon-bar {
    border: 1px solid;
    position: relative
}
.navbar .navbar-nav>li {
    margin: 0
}
.navbar .navbar-nav>li>a {
    text-transform: uppercase
}
.navbar .navbar-nav>li a {
    padding-top: 15px;
    padding-bottom: 15px;
    border-radius: 3px;
    color: inherit
}
.navbar .navbar-nav>li .dropdown-menu {
    margin-top: -5px;
    border: none
}
.navbar .navbar-nav>li .dropdown-menu li {
    color: #333;
    position: relative
}
.navbar .navbar-nav>li .dropdown-menu li>a {
    background-color: transparent;
    margin: 0 5px;
    padding: 10px;
    border-radius: 2px
}
.navbar .navbar-nav>li:not(.btn)>a:before {
    position: absolute;
    z-index: -1;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: 3px;
    background-color: rgba(255, 255, 255, .1);
    content: "";
    -webkit-transform: scaleX(0);
    -ms-transform: scaleX(0);
    transform: scaleX(0);
    -webkit-transform-origin: 50%;
    -ms-transform-origin: 50%;
    transform-origin: 50%
}
#main-navigation ul.nav>li {
    opacity: 1;
    visibility: visible
}
.hestia-about {
    padding: 65px 0 30px
}
.hestia-about {
    background-attachment: fixed;
    color: #999
}
.hestia-about h2,.hestia-about h4 {
    color: #3c4858;
    text-decoration: none;
    word-wrap: break-word;
    font-family: "Roboto Slab", "Times New Roman", serif
}
.blog-post {
    word-wrap: break-word
}
.main {
    position: relative;
    background: #fff
}
.main-raised {
    margin: -60px 30px 0;
    border-radius: 6px 6px 0 0;
    -webkit-box-shadow: 0 16px 24px 2px rgba(0, 0, 0, .14), 0 6px 30px 5px rgba(0, 0, 0, .12), 0 8px 10px -5px rgba(0, 0, 0, .2);
    box-shadow: 0 16px 24px 2px rgba(0, 0, 0, .14), 0 6px 30px 5px rgba(0, 0, 0, .12), 0 8px 10px -5px rgba(0, 0, 0, .2)
}
.home .main-raised section:first-of-type {
    border-radius: 6px 6px 0 0;
    overflow: hidden
}
@media (max-width:1199px) {
    .hestia-about .row {
        padding: 0 15px
}
    .main-raised {
        margin: -60px 15px 0
}
}
@media (max-width:991px) {
    .navbar .navbar-nav>li {
        margin-right: 10px;
        margin-left: 10px
}
    .hestia-about .row {
        padding: 0 10px
}
}
@media (min-width:992px) {
    .navbar .navbar-collapse {
        text-align: center
}
    .navbar .navbar-nav>li {
        margin: 0
}
}
@media (min-width:769px) {
    .navbar.hestia_left .title-logo-wrapper {
        min-width: 250px
}
    .dropdown .dropdown-menu {
        display: block;
        visibility: hidden;
        margin-top: -20px;
        opacity: 0
}
}
@media (max-width:768px) {
    .container .navbar-header {
        width: 100%;
        display: flex;
        margin: 0 auto
}
    .navbar>.container {
        padding: 10px 15px;
        align-items: center;
        display: block
}
    .navbar .nav.navbar-nav {
        display: block
}
    .navbar.navbar-fixed-top .navbar-collapse {
        max-height: calc(100% - 70px);
        margin-top: 70px;
        overflow-y: auto;
        position: fixed;
        z-index: 9999;
        background: #fff;
        width: 100%;
        left: 0;
        top: 0;
        margin-left: 0;
        margin-right: 0;
        -webkit-overflow-scrolling: auto
}
    .navbar .navbar-nav {
        margin: 7.5px 0
}
    .navbar .navbar-nav li {
        box-sizing: border-box;
        float: left;
        margin: 0;
        padding: 0;
        width: 100%;
        text-align: left
}
    .navbar .navbar-nav .dropdown a .caret {
        border: 1px solid #555;
        border-radius: 2px;
        box-sizing: content-box;
        color: #555;
        display: inline-block;
        font-family: "Font Awesome 5 Free";
        font-weight: 900;
        height: 30px;
        margin-left: 0;
        position: absolute;
        right: 15px;
        text-align: center;
        top: 10px;
        width: 30px;
        z-index: 100
}
    .navbar .navbar-nav .dropdown a .caret:before {
        content: "\f107";
        top: 5px;
        position: relative;
        display: inline-block
}
    .navbar .navbar-nav .dropdown .dropdown-menu {
        background: 0 0;
        box-shadow: none;
        position: static;
        margin-top: 0;
        padding: 0;
        width: 100%
}
    .navbar .navbar-nav .dropdown .dropdown-menu li a {
        margin: 0;
        padding: 15px 0 15px 30px
}
    .navbar .navbar-header .navbar-brand {
        padding-left: 0
}
    .home .main-raised section:first-of-type {
        border-radius: 0
}
    .main-raised {
        margin-right: 0;
        margin-left: 0;
        border-radius: 0
}
    .hestia-about {
        padding-top: 30px
}
    .hestia-about h2 {
        margin-top: 0
}
    .home:not(.blog) .main-raised {
        margin-top: 0
}
}
.elementor-page .hestia-about>.container {
    width: 100%
}
.home.elementor-page .main-raised>section.hestia-about {
    overflow: visible
}
.elementor-text-editor p {
    font-size: inherit
}
a {
    color: #002970
}
button {
    background-color: #002970
}
h2,h4,.hestia-about h2,.hestia-about h4 {
    font-family: Sanchez
}
body,ul {
    font-family: Sanchez
}
.sr-only {
    border: 0;
    clip: rect(0, 0, 0, 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px
}
@font-face {
    font-family: "Font Awesome 5 Free";
    font-style: normal;
    font-weight: 400;
    font-display: auto;
    src: url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-regular-400.eot);
    src: url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-regular-400.eot?#iefix) format("embedded-opentype"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-regular-400.woff2) format("woff2"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-regular-400.woff) format("woff"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-regular-400.ttf) format("truetype"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-regular-400.svg#fontawesome) format("svg")
}
@font-face {
    font-family: "Font Awesome 5 Free";
    font-style: normal;
    font-weight: 900;
    font-display: auto;
    src: url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-solid-900.eot);
    src: url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-solid-900.eot?#iefix) format("embedded-opentype"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-solid-900.woff2) format("woff2"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-solid-900.woff) format("woff"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-solid-900.ttf) format("truetype"), url(//analogninja.de/wp-content/themes/hestia/assets/font-awesome/css/../webfonts/fa-solid-900.svg#fontawesome) format("svg")
}
.elementor-clearfix:after {
    content: "";
    display: block;
    clear: both;
    width: 0;
    height: 0
}
.elementor {
    -webkit-hyphens: manual;
    -ms-hyphens: manual;
    hyphens: manual
}
.elementor *,.elementor:after,.elementor:before {
    -webkit-box-sizing: border-box;
    box-sizing: border-box
}
.elementor a {
    -webkit-box-shadow: none;
    box-shadow: none;
    text-decoration: none
}
.elementor img {
    height: auto;
    max-width: 100%;
    border: none;
    -webkit-border-radius: 0;
    border-radius: 0;
    -webkit-box-shadow: none;
    box-shadow: none
}
.elementor-section {
    position: relative
}
.elementor-section .elementor-container {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    margin-right: auto;
    margin-left: auto;
    position: relative
}
.elementor-section.elementor-section-boxed>.elementor-container {
    max-width: 1140px
}
.elementor-row {
    width: 100%;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex
}
@media (max-width:1024px) {
    .elementor-row {
        -webkit-flex-wrap: wrap;
        -ms-flex-wrap: wrap;
        flex-wrap: wrap
}
}
.elementor-column-wrap {
    width: 100%;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex
}
.elementor-widget-wrap {
    position: relative;
    width: 100%;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-align-content: flex-start;
    -ms-flex-line-pack: start;
    align-content: flex-start
}
.elementor:not(.elementor-bc-flex-widget) .elementor-widget-wrap {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex
}
.elementor-widget-wrap>.elementor-element {
    width: 100%
}
.elementor-widget {
    position: relative
}
.elementor-column {
    position: relative;
    min-height: 1px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex
}
.elementor-column-gap-default>.elementor-row>.elementor-column>.elementor-element-populated {
    padding: 10px
}
@media (min-width:768px) {
    .elementor-column.elementor-col-100 {
        width: 100%
}
}
@media (max-width:767px) {
    .elementor-column {
        width: 100%
}
}
.elementor-widget-heading .elementor-heading-title {
    padding: 0;
    margin: 0;
    line-height: 1
}
.elementor-widget-heading .elementor-heading-title {
    font-family: "Sanchez", Sans-serif;
    font-weight: 600
}
.elementor-widget-text-editor {
    font-family: "Sanchez", Sans-serif;
    font-weight: 400
}
.elementor-386 .elementor-element.elementor-element-b5f43bf>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-b5f43bf {
    margin-top: -40px;
    margin-bottom: 0
}
.elementor-386 .elementor-element.elementor-element-6dfb8a4.elementor-widget-heading .elementor-heading-title {
    color: #0c0c0c
}
.elementor-386 .elementor-element.elementor-element-6dfb8a4 .elementor-heading-title {
    font-family: "Sanchez", Sans-serif;
    font-weight: 700
}
.elementor-386 .elementor-element.elementor-element-5451f39>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-fe48f01 {
    color: #0c0c0c;
    font-size: 1.3em
}
.elementor-386 .elementor-element.elementor-element-14a2f0a>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-061141d.elementor-widget-heading .elementor-heading-title {
    color: #0f0f0f
}
.elementor-386 .elementor-element.elementor-element-1284051>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-7755a44 {
    color: #0c0c0c;
    font-size: 1.3em
}
.elementor-386 .elementor-element.elementor-element-c88de32>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-7c59ba1.elementor-widget-heading .elementor-heading-title {
    color: #0c0c0c
}
.elementor-386 .elementor-element.elementor-element-39a07a8>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-f0bdcd3 {
    color: #0c0c0c;
    font-size: 1.3em
}
.elementor-386 .elementor-element.elementor-element-d63182f>.elementor-container {
    max-width: 900px
}
.elementor-386 .elementor-element.elementor-element-953030e .obfx-grid-col-image {
    height: 230px;
    border-radius: 15px;
    margin: 0
}
.elementor-386 .elementor-element.elementor-element-953030e .obfx-grid-wrapper {
    padding-right: calc(15px);
    padding-left: calc(15px);
    padding-bottom: 30px
}
.elementor-386 .elementor-element.elementor-element-953030e .obfx-grid-container {
    margin-left: calc(-15px);
    margin-right: calc(-15px)
}
@media (max-width:767px) {
    .elementor-386 .elementor-element.elementor-element-b5f43bf {
        margin-top: -15px;
        margin-bottom: 0
}
    .elementor-386 .elementor-element.elementor-element-6dfb8a4>.elementor-widget-container {
        margin: 10px 0 0
}
    .elementor-386 .elementor-element.elementor-element-fe48f01 {
        font-size: 1.1em
}
    .elementor-386 .elementor-element.elementor-element-7755a44 {
        font-size: 1.1em
}
    .elementor-386 .elementor-element.elementor-element-f0bdcd3 {
        font-size: 1.1em
}
    .elementor-386 .elementor-element.elementor-element-953030e .obfx-grid-wrapper {
        padding-right: calc(0px);
        padding-left: calc(0px);
        padding-bottom: 10px
}
    .elementor-386 .elementor-element.elementor-element-953030e .obfx-grid-container {
        margin-left: calc(0px);
        margin-right: calc(0px)
}
}
body.custom-background {
    background-color: #686868
}
.navbar .navbar-header .navbar-brand img {
    max-height: 60px
}
.navbar .navbar-nav>li>a {
    font-size: 14px!important
}
a {
    color: #1e8dfc
}
.lazyload {
    opacity: 0
}
.obfx-grid:after {
    display: block;
    visibility: hidden;
    clear: both;
    height: 0;
    font-size: 0;
    content: " "
}
.obfx-grid-container {
    display: -webkit-flex;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    margin-right: -15px;
    margin-left: -15px;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap
}
.obfx-grid-wrapper {
    padding-right: 15px;
    padding-left: 15px
}
.obfx-grid .obfx-grid-col-image {
    display: block;
    overflow: hidden;
    position: relative;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: 0 0 10px;
    box-shadow: 0 3px 10px 0 rgba(181, 181, 181, 1)
}
.obfx-grid .obfx-grid-col-image {
    display: inline-block;
    width: 100%;
    height: 200px
}
.obfx-grid .obfx-grid-col-image img {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: none;
    -webkit-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%)
}
.obfx-grid-desktop-1 .obfx-grid-wrapper {
    width: 100%
}

应该是:

-ArgumentList @(${ELEVATED_USER},\$secpasswd)

您必须引用第一个参数,因为它是PowerShell数组构造函数中的Groovy变量。如果不加引号,groovy编译器将按以下方式评估PowerShell脚本的字符串:

-ArgumentList @("${ELEVATED_USER}",\$secpasswd)

这不是有效的PowerShell语法。