How to check if build parameter is available in Jenkinsfile

后端 未结 5 564
Happy的楠姐
Happy的楠姐 2021-02-07 15:16

I have a pipeline script that should work with and without parameters. So I have to check if the parameter is available.

I tried if(getBinding().hasVariable(\"mypa

5条回答
  •  终归单人心
    2021-02-07 15:45

    This is how I did that:

    def myParam = false
    if (params.myParam != null){
        myParam = params.myParam
    }
    

    Why do that at all when you can just define parameters in your pipeline as suggested above?

    Well, there are situations when you want your pipeline file to work regardless of if parameter is defined or not. I.e., if you're re-using your pipeline script from different Jenkins jobs and you don't want to make people define that parameter ...

提交回复
热议问题