【问题标题】:Using variable as Jenkins input message text使用变量作为 Jenkins 输入消息文本
【发布时间】:2021-08-20 13:03:26
【问题描述】:

我想在脚本化管道的输入步骤中使用变量作为消息。

stage("Manual Approval"){
        sh """
        ls -la
        versionNumber=`grep -wE -A 2 '"package": "example0"'`
        ancestorVersion=`grep -wE -A 2 '"package": "example"'`
        """
        timeout(time: 120, unit: 'MINUTES') {
            input message: "Do you want to build ver. ${versionNumber} having ver. ${ancestorVersion} as an ancestor?", submitter: 'user1'
        }
    }

【问题讨论】:

    标签: shell jenkins input jenkins-pipeline


    【解决方案1】:

    在最新版本的管道sh 步骤中允许将输出保存在一个变量中,如下:

    script {
        INFO_SYSTEM = sh (
            script: 'uname -a',
            returnStdout: true
        ).trim()
        echo "Value: ${INFO_SYSTEM}"
    }
    

    输出:

    Running on Jenkins in /var/jenkins_home/workspace/testing
    [Pipeline] {
    [Pipeline] stage
    [Pipeline] { (Testing)
    [Pipeline] script
    [Pipeline] {
    [Pipeline] sh
    + uname -a
    [Pipeline] echo
    Value: Linux d7d184735414 4.14.225-121.357.amzn1.x86_64 #1 SMP Mon Mar 15 23:52:05 UTC 2021 x86_64 GNU/Linux
    [Pipeline] }
    [Pipeline] // script
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    Finished: SUCCESS
    

    所以,也许您可​​以更改执行此任务的方法,让每个变量在单个命令中执行并检索输出,如下所示:

    stage("Manual Approval"){
        VERSION_NUMBER = sh (
                script: 'grep -wE -A 2 '"package": "example0"'',
                returnStdout: true
            ).trim()
    
        ANCESTOR_VERSION = sh (
                script: 'grep -wE -A 2 '"package": "example"'',
                returnStdout: true
            ).trim()
    
        timeout(time: 120, unit: 'MINUTES') {
                input message: "Do you want to build ver. ${VERSION_NUMBER} having ver. ${ANCESTOR_VERSION} as an ancestor?", submitter: 'user1'
            }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      相关资源
      最近更新 更多