我正在尝试使用配置作为代码(JCasC)插件来创建一个接受构建参数的管道作业,但是我无法在线找到这方面的语法。我正在用YAML编写配置。
在GUI上,该字段称为“此构建是参数化的”,它位于“General”标题下。我需要定义两个字符串参数: CLUSTER_ID=cluster_id和OPENSHIFT_ADMINSTRATION_BRANCH=develop。
这是我试图编辑的yaml文件:
jobs:
- script: >
folder('test1'){
pipelineJob('test1/seedJobTest') {
description 'seedJobTest'
logRotator {
daysToKeep 10
}
definition {
cpsScm {
scm {
git {
remote {
credentials "xxx"
url 'xxx'
}
branches 'refs/head/master'
scriptPath 'Jenkinsfile'
extensions { }
}
}
}
}
configure { project ->
project / 'properties' / 'EnvInjectJobProperty' {
'on'('true')
}
project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty' {}
}
}
}谢谢你的帮忙!
发布于 2019-12-31 17:46:35
解决方案
jobs:
- script: >
folder('test1'){
pipelineJob('test1/seedJobTest') {
description 'seedJobTest'
logRotator {
daysToKeep 10
}
parameters {
stringParam("CLUSTER_ID", "cluster_id", "your description here")
stringParam("OPENSHIFT_ADMINSTRATION_BRANCH", "develop", "your description here")
}
definition {
cpsScm {
scm {
git {
remote {
credentials "xxx"
url 'xxx'
}
branches 'refs/head/master'
scriptPath 'Jenkinsfile'
extensions { }
}
}
}
}
configure { project ->
project / 'properties' / 'EnvInjectJobProperty' {
'on'('true')
}
project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty' {}
}
}
}如何在未来解决这个问题- XML作业到DSL (Jenkins插件)
以下是我如何理解这类事情:
automate).
当我开始获得这个答案的params片段时,我做了上面描述的事情,但只创建了两个参数。最后我得到了这个:
pipelineJob("test") {
description()
keepDependencies(false)
parameters {
stringParam("CLUSTER_ID", "cluster_id", "your description here")
stringParam("OPENSHIFT_ADMINSTRATION_BRANCH", "develop", "your description here")
}
definition {
cpsScm {
"" }
}
disabled(false)
}只读参数选项
还有一件事,万一它对你有用(就像对我一样)。如果您想要创建一个参数化的种子作业,但不希望这些作业在构建时是可编辑的,您可以安装“只读参数”Jenkins插件;然后,您可以这样做:
jobs:
- script: >
pipelineJob("Param Example") {
description()
keepDependencies(false)
parameters {
wHideParameterDefinition {
name('AGENT')
defaultValue('docker-host')
description('Node on which to run.')
}
wHideParameterDefinition {
name('ENV_FILE_DIR')
defaultValue('local2')
description('Name of environment directory which houses .env')
}
booleanParam("include_search_stack", false, "Build/run the local Fess, Elasticsearch, and Kibana containers.")
booleanParam("SKIP_404_GENERATION", false, "Helpful sometimes during local development.")
}
definition {
cpsScm {
scm {
git {
remote {
url("https://myrepo/blah.git")
credentials("scm")
}
branch("master")
}
}
scriptPath("pipeline/main/Jenkinsfile")
}
}
disabled(false)
}在本例中,前两个参数AGENT和ENV_FILE_DIR是CasC的“硬编码”,因为这些参数在构建时是不可编辑的。但是,include_search_stack和SKIP_404_GENERATION参数是可编辑的。我使用了这个混合的例子来说明这两种方法在同一个作业中都是可用的。
只读参数在我的一些用例中很有用。
https://stackoverflow.com/questions/58401863
复制相似问题