相关疑难解决方法(0)

groovy中单引号或双引号中字符串的区别是什么?

def a = "a string"
def b = 'another'
Run Code Online (Sandbox Code Playgroud)

有什么区别吗?或者就像javascript让我们输入'"更容易在字符串中?

string groovy

83
推荐指数
2
解决办法
3万
查看次数

从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万
查看次数

在 jenkins 管道 sh 步骤中使用嵌套命令替换

我试图在归档之前使用指向相关内部文件夹的符号链接来展平结果目录,该文件夹首先遍历在运行时确定的一堆变量路径名。我似乎无法使用我从这个 SO answer中学到的这种命令替换方法来获得正确的语法。

问题:是否有关于如何从我不知道的 Jenkins 管道步骤正确转义命令替换链的规则?

流水线脚本片段

post {
  always {   
    sh """
    echo 'Link to inner output result folder to make the artifacts more shallow'
    echo ln -sf dirname find $output_dir -name $jUnitResult $WORKSPACE/$output_dir_inner
    ln -sf $(dirname $(find ${output_dir} -name ${jUnitResult})) $WORKSPACE/$output_dir_inner
    """

    archiveArtifacts output_dir_inner
  }
}
Run Code Online (Sandbox Code Playgroud)

控制台输出

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 52: illegal string body character after dollar sign;
   solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 52, column …
Run Code Online (Sandbox Code Playgroud)

sh jenkins jenkins-pipeline

8
推荐指数
1
解决办法
3565
查看次数

在詹金斯管道的多个步骤中定义和访问变量

我是从这篇文章《在 Jenkins Pipeline 的 shell 脚本部分定义变量》来到这里的

我的情况如下:如果生成的文件发生更改(它们每几周或更短时间更改一次),我有一个管道正在更新一些文件并在我的存储库中生成 PR。

在管道的最后,我有一个后操作,通过电子邮件将结果发送到我们的团队连接器。

我想知道是否可以以某种方式生成一个变量并将该变量包含在我的电子邮件中。

它看起来像这样,但当然它不起作用。

#!groovy
String WasThereAnUpdate = '';

pipeline {
    agent any
    environment {
        GRADLE_OPTS = '-Dorg.gradle.java.home=$JAVA11_HOME'
    }
    stages {
        stage('File Update') {
            steps {
                sh './gradlew updateFiles -P updateEnabled'
            }
        }
        stage('Create PR') {
            steps {
                withCredentials(...) {
                    sh '''
                        if [ -n \"$(git status --porcelain)\" ]; then
                            WasThereAnUpdate=\"With Updates\"
                            ...
                        else
                            WasThereAnUpdate=\"Without updates\"
                        fi
                    '''
                }
            }    
        }
    }
    post {
        success {
            office365ConnectorSend(
                message: "Scheduler finished: " + …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-pipeline

2
推荐指数
1
解决办法
4590
查看次数

标签 统计

jenkins ×3

jenkins-pipeline ×3

groovy ×1

sh ×1

string ×1