相关疑难解决方法(0)

从Jenkins管道中的shell步骤中访问Groovy变量

使用Jenkins 2.x中Pipeline插件,如何在sh步骤中访问在阶段或节点级某处定义的Groovy变量?

简单的例子:

node {
    stage('Test Stage') {
        some_var = 'Hello World' // this is Groovy
        echo some_var // printing via Groovy works
        sh 'echo $some_var' // printing in shell does not work
    }
}
Run Code Online (Sandbox Code Playgroud)

在Jenkins输出页面上给出以下内容:

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test Stage)
[Pipeline] echo
Hello World
[Pipeline] sh
[test] Running shell script
+ echo

[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Run Code Online (Sandbox Code Playgroud)

可以看出,echo …

jenkins jenkins-pipeline

28
推荐指数
3
解决办法
5万
查看次数

如何将 groovy 变量传递给 shell 块 jenkins

我有一个 groovy 变量,我想将其传递给 shell 块以进行进一步处理,但是我不断收到以下粘贴的错误:

stages {      
    stage('First Stage - echo out available variables'){
        steps{

            script {
                def string_var = "im a groovy variable"
                echo "${string_var}"   // This will print "im a groovy variable" just fine
                sh """
                    echo """ + string_var + """
                """  // This will error

                sh """
                    echo ${string_var} 
                """  // This will error

                sh ''' echo '''+ string_var +''' '''

                sh "echo ${string_var}" // This will error
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的错误:

an exception which …
Run Code Online (Sandbox Code Playgroud)

groovy jenkins

3
推荐指数
1
解决办法
5736
查看次数

标签 统计

jenkins ×2

groovy ×1

jenkins-pipeline ×1