How do pipeline parameters and jenkins GUI parameters work together?

后端 未结 2 1221
我寻月下人不归
我寻月下人不归 2021-02-03 12:41

I am using a pipeline in a jenkinsfile and I am not sure how to properly link the job in Jenkins and the pipeline.

I defined parameters in my jenkinsfile (some with def

2条回答
  •  长情又很酷
    2021-02-03 12:55

    This problem can be solved by adding a special parameter to avoid default values being override. Here is the sample code.

    if (!params.__INIT__) { // this value will be true once parameters get initialized
        properties([ parameters([
                string(name: 'SOURCE_URL', trim: true),
                string(name: 'TARGET_URL', trim: true),
    
                string(name: 'DEPLOY_URL', trim: true),
                credentials(name: 'DEPLOY_KEY', required: true ),
    
                string(name: 'BUILD_NODE', trim: true),
    
                booleanParam(name: '__INIT__', defaultValue: true, description: "Uncheck this field in configuration page and run this job once if you want to re init parameter."),
        ]) ])
        return // exit 
    }
    
    // Your task stars from here
    
    

    By doing this way, the parameters won't be initialized again next time because __INIT__ has been set to true. On the other hand, if you update your script and change some parameters, you can just run the job by unchecking the __INIT__ field.

提交回复
热议问题