Jenkins配置为代码插件(JCasC)的参数化生成语法

Jenkins配置为代码插件(JCasC)的参数化生成语法,jenkins,yaml,jenkins-pipeline,jenkins-plugins,jcasc,Jenkins,Yaml,Jenkins Pipeline,Jenkins Plugins,Jcasc,我试图使用配置为代码(JCasC)插件来创建一个接受构建参数的管道作业,但我在网上任何地方都找不到该作业的语法。我正在用YAML编写配置 在GUI上,该字段称为“此构建已参数化”,并位于“常规”标题下。我需要定义两个字符串参数:CLUSTER\u ID=CLUSTER\u ID和OPENSHIFT\u administration\u BRANCH=developer 这是我正在尝试编辑的yaml文件: jobs: - script: > folder('test1'){

我试图使用配置为代码(JCasC)插件来创建一个接受构建参数的管道作业,但我在网上任何地方都找不到该作业的语法。我正在用YAML编写配置

在GUI上,该字段称为“此构建已参数化”,并位于“常规”标题下。我需要定义两个字符串参数:CLUSTER\u ID=CLUSTER\u ID和OPENSHIFT\u administration\u BRANCH=developer

这是我正在尝试编辑的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' {}
          }
        }
      }
谢谢你的帮助

解决方案 如何在将来解决这个问题-DSL的XML工作(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)
      }
  • 手动创建一个临时管道作业,其中包含您希望在种子作业(您希望自动执行的作业)中包含的内容
  • 安装(如果只是暂时安装)“XML作业到DSL”Jenkins插件
  • 转到詹金斯主仪表板
  • 在左侧导航中,您将找到“XML作业到DSL”
  • 选择您创建的临时作业,然后单击“将所选内容转换为DSL”
当我开始获取这个答案的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; u GENERATION
参数是可编辑的。我使用这个混合示例来说明其中一个/两个都可以在同一个作业中使用

只读参数在我的一些用例中很有用