如何在管道中使用Jenkins字符串参数 [英] How to use Jenkins String Parameter in pipeline

查看:116
本文介绍了如何在管道中使用Jenkins字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Jenkins Pipeline在jenkins中配置作业.对于一堆作业,我们需要使用参数化构建的用户输入,用户可以在其中输入参数值,然后在.jenkins文件中使用sh

We am using Jenkins Pipeline to configure jobs in jenkins. For a bunch of jobs we need user input for which we use parameterised build where user can input parameter values and later we use the values in our .jenkinsfile in sh like

 sh "./build-apply.sh ${accountnumber} ${volumename} ${vpcname} services ${snapshotid}"

这曾经与

  • 詹金斯2.16
  • 管道2.3
  • Groovy 2.15

但是,当我将Jenkins重建为:

However, when I rebuild Jenkins to:

  • 2.16或最新的2.26
  • 管道2.5
  • 管道:Groovy 2.19

以上sh停止工作.错误

groovy.lang.MissingPropertyException: No such property: accountnumber for class: groovy.lang.Binding

知道我想念的是什么吗?语法不正确吗?

Any idea what I am missing? Is the syntax not correct?

供参考全文Jenkinsfile供参考

node {
  // Mark the code checkout 'stage'....


  stage 'Checkout'
  git branch: '****', credentialsId: '***', url: '****'

  stage 'Provision Volume'
  withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: '*****',
                    credentialsId: '****',
                    secretKeyVariable: '*****']]) {
    // Run the terraform build
    env.PATH = "${env.PATH}:/jenkins/terraform"
    sh "./build-apply.sh ${accountnumber} ${volumename} ${vpcname} services ${snapshotid}"
  }
}

推荐答案

将以下代码复制并粘贴到管道脚本中 节点:{

Copy and paste the below code in the pipeline script node: {

stage ('BCCdlVsLib') {
build job: 'BCCdlVsLib', parameters:
[
    [$class: 'StringParameterValue', name: 'BINPATH', value: 'BINPATH'], 
    [$class: 'StringParameterValue', name: 'SOURCEFILE', value: 'SOURCEFILE']
        ]
}

在作业(BCCdlVsLib)中,启用选项此项目已参数化",然后输入2个字符串参数job_binpath,job_sourcefile.

In the jobs (BCCdlVsLib) enable the option "this project is parametrized" and enter 2 string parameters job_binpath,job_sourcefile.

打印管道作业中的变量 回声job_binpath 回声job_sourcefile

Print the variables in the pipeline jobs echo job_binpath echo job_sourcefile

运行管道作业后,将获得以下输出. 二进制路径 源文件

After run the pipeline job,will get the below output. BINPATH SOURCEFILE

这篇关于如何在管道中使用Jenkins字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆