英文:
Jenkins Pipeline passing parameter as shell script argument
问题
我有一个带有默认值的参数化的Jenkins Pipeline,我试图将该参数作为脚本参数传递,但似乎没有传递任何东西。以下是脚本:
pipeline {
agent any
stages {
stage('Building') {
steps {
build job: 'myProject', parameters: [string(name: 'configuration', value: '${configuration}')]
}
}
stage('Doing stuff') {
steps {
sh "~/scripts/myScript ${configuration}"
}
}
}
}
它似乎对构建步骤起作用,但对于脚本来说不起作用。它返回一个错误,说我没有参数。
我尝试用${configuration}
,${params.configuration}
和$configuration
来获取它。
正确的方法是如何访问参数并将其正确传递到脚本中?
谢谢。
英文:
I have a parameterized Jenkins Pipeline with a default value and I'm trying to pass that param as a script argument but it doesn't seem to pass anything. Here is the script :
pipeline {
agent any
stages {
stage('Building') {
steps {
build job: 'myProject', parameters: [string(name: 'configuration', value: '${configuration}')]
}
}
stage('Doing stuff') {
steps {
sh "~/scripts/myScript ${configuration}"
}
}
}
}
It seems to work for the build step but not for the script. I returns an error saying I have no argument.
I tried to get it with ${configuration}
, ${params.configuration}
and $configuration
.
What is the right way to access a param and pass it correctly to a script ?
Thanks.
答案1
得分: 1
以下是翻译好的部分:
实际上,您正在使用构建步骤来传递参数给Jenkins作业 'myProject'。
build job: 'myProject', parameters: [string(name: 'configuration', value: '${configuration}')]
如果您想在此作业中声明一个参数,您需要在 "parameters" 块中声明您的参数。
pipeline {
agent any
parameters {
string(defaultValue: '', description: '', name: 'configuration')
}
stages {
stage('Doing stuff') {
steps {
sh "~/scripts/myScript ${configuration}"
}
}
}
}
英文:
Actually, you are using the build step, to pass a parameter to the Jenkins job 'myProject'.
build job: 'myProject', parameters: [string(name: 'configuration', value: '${configuration}')]
If you want to declare a Parameter in this job you need to declare your parameter in a "parameters" block.
pipeline {
agent any
parameters {
string(defaultValue: '', description: '', name: 'configuration')
}
stages {
stage('Doing stuff') {
steps {
sh "~/scripts/myScript ${configuration}"
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论