How do I pass variables between stages in a declarative Jenkins pipeline?

后端 未结 3 1794
情书的邮戳
情书的邮戳 2020-12-01 01:01

How do I pass variables between stages in a declarative pipeline?

In a scripted pipeline, I gather the procedure is to write to a temporary file, then read the file

3条回答
  •  爱一瞬间的悲伤
    2020-12-01 01:34

    Simply:

      pipeline {
            parameters {
                string(name: 'custom_var', defaultValue: '')
            }
    
            stage("make param global") {
                 steps {
                   tmp_param =  sh (script: 'most amazing shell command', returnStdout: true).trim()
                   env.custom_var = tmp_param
                  }
            }
            stage("test if param was saved") {
                steps {
                  echo "${env.custom_var}"
                }
            }
      }
    

提交回复
热议问题