Jenkins 如何将参数传递给DSL中的pipelineJob
我有非常相似的管道作业,只有参数不同。目标是通过在DSL脚本中传递参数来创建这些作业,而无需任何代码复制 我跟着。因此,如果在实现了本文中提到的步骤之后运行下面的DSL脚本,我的脚本就可以运行了 TL;博士 在那篇文章中,我们添加了一个共享库,并让Jenkinsfile使用该共享库 我有一个非常相似的方法。不同之处在于我希望通过DSL创建构建作业,并通过DSL上的设置更改Jenkins文件的默认参数 问题是如何在Jenkins文件中传递/覆盖参数Jenkins 如何将参数传递给DSL中的pipelineJob,jenkins,groovy,jenkins-pipeline,jenkins-job-dsl,Jenkins,Groovy,Jenkins Pipeline,Jenkins Job Dsl,我有非常相似的管道作业,只有参数不同。目标是通过在DSL脚本中传递参数来创建这些作业,而无需任何代码复制 我跟着。因此,如果在实现了本文中提到的步骤之后运行下面的DSL脚本,我的脚本就可以运行了 TL;博士 在那篇文章中,我们添加了一个共享库,并让Jenkinsfile使用该共享库 我有一个非常相似的方法。不同之处在于我希望通过DSL创建构建作业,并通过DSL上的设置更改Jenkins文件的默认参数 问题是如何在Jenkins文件中传递/覆盖参数 // BTW I'll run this cod
// BTW I'll run this code below in a loop. Open for any suggesstion
pipelineJob('AwesomeBild') {
description("A pipeline created by dsl")
definition {
cpsScm {
scm {
git {
remote { url('https://github.com/jalogut/jenkinsfile-shared-library-sample.git') }
branches('master')
// how can I pass params to the file
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}
编辑
参数运行良好。这是DSL文件的最新版本
pipelineJob('AwesomeBild') {
description("A pipeline created by dsl")
parameters {
stringParam( "key", "value" )
}
definition {
cpsScm {
scm {
git {
remote { url('https://github.com/jalogut/jenkinsfile-shared-library-sample.git') }
branches('master')
// how can I pass params to the file
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}
解决方案很简单:
只需使用$key,但保留单引号:
scriptPath('Jenkinsfile$key')
环境变量?我试过了。它不起作用。也许我不能。这显示了如何通过DSL创建的作业将参数从DSL作业传递到管道: