Is it possible to make a parameterized scripted pipeline in Jenkins by listing the parameters in actual script, not in job config

后端 未结 4 2104
再見小時候
再見小時候 2021-02-12 14:51

In a declarative pipeline, I can specify the parameter that the pipeline expects right in the pipeline script like so:

pipeline {
   parameters([
    string(name         


        
4条回答
  •  生来不讨喜
    2021-02-12 15:07

    You can use Jenkins job DSL plugin for generating jobs, pipelines, multi-branch pipelines... The DSL allows the definition of a job, and then offers a useful set of functions to configure common Jenkins items. A configure is available to give direct access to the config.xml before generating the job. With parameters block you can then easily define any type of parameters with their default values and description. Note that this plugin is also compatible with git and other version control systems.

    jobDsl scriptText: ''' job('example') {
        parameters {
            stringParam('Parameter Name', 'Default Value' , 'Parameter Description')
        }
        scm {
            perforceP4('p4_credentials') {
                workspace {
                    manual('ws_name', '//depot/Tools/build/... //ws_name/build/...')
                }
            configure { node ->
                        node / workspace / spec / clobber('true')
                }
            }
        }
    }'''
    

    References:

    https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-perforceP4

    https://wiki.jenkins.io/display/JENKINS/Job+DSL+Plugin

提交回复
热议问题