[英]Parameterisation of a groovy Pipeline for use with jenkins
I have a groovy pipeline which I've inherited from a project that I forked.我有一个 groovy 管道,它是从我分叉的项目中继承的。
I wish to pass in Jenkins Choice Parameters as a Parameterised build.我希望将 Jenkins 选择参数作为参数化构建传递。 At present, I only wish to expose the environment in which to run ( but will want to parameterise further at a later stage), such that a user can choose it from the Jenkins dropdown and use on demand.
目前,我只希望公开运行环境(但希望在稍后阶段进一步参数化),以便用户可以从 Jenkins 下拉列表中选择它并按需使用。
I used the snippet generator to help.我使用了代码片段生成器来提供帮助。
Can someone please help with the syntax?有人可以帮忙语法吗? I am using Node with a package.json to run a script and with to pass in either
dev
or uat
:我正在使用带有 package.json 的 Node 来运行脚本并传入
dev
或uat
:
properties([[$class: 'BuildConfigProjectProperty', name: '', namespace: '', resourceVersion: '', uid: ''], parameters([choice(choices: 'e2e\nuat', description: 'environment ', name: 'env')])])
node('de-no1') {
try {
stage('DEV: Initialise') {
git url: 'https://myrepo.org/mycompany/create-new-user.git', branch: 'master', credentialsId: CREDENTIALS_ID
}
stage('DEV: Install Dependencies') {
sh 'npm install'
}
stage('${params.env}: Generate new users') {
sh 'npm run generate:${params.env}'
archiveArtifacts artifacts: '{params.env}-userids.txt', fingerprint: true
}
This currently fails with:这目前失败:
npm ERR! missing script: generate:{params.env}
Assume you want to replace ${params.env}
with a value when you call npm?假设你想在调用 npm 时将
${params.env}
替换为一个值?
If this is the case, you need to use double quotes "
to let Groovy know you will be doing String templating...ie:如果是这种情况,您需要使用双引号
"
让 Groovy 知道您将执行字符串模板...即:
sh "npm run generate:${params.env}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.