Jenkins Pipeline check if parameterized build is really parameterized

Clash Royale CLAN TAG#URR8PPP
Jenkins Pipeline check if parameterized build is really parameterized
Currently i am working with Jenkins pipelines and parameterized builds.
I know i can start a pipeline stage where i can check if the given parameters are empty or not, but is there another way how to check if a parameterized build is really parameterized?
Like a step before i go into stages?
A stage where we can check some conditions before going into the stages.
when expression params.skipTests != "Yes"
script
return
Jenkins Pipelines works with stages , but before entering the first stage , i want to run a block where i can test if the parameters are not invalid,i would like to know how this could be achieved in a Pipeline script, my approach was to create another stage and check the conditions in that stage but i would like to know for future pipeline scrips , if there is a method to do some precheck things before entering the first stage
– Onur Kadem
Aug 10 at 11:42
1 Answer
1
In Declarative Pipeline where is no way run something 'before'. You can run another job which trigger 'the job' or try something like this, if some parameters not pass validation whole job will be aborted. But You can control that in script block.
script
def ex(param)
currentBuild.result = 'ABORTED'
error('BAD PARAM: ' + param)
pipeline
agent any
parameters
choice(name: 'a', choices:"NOnOKnMaybe", description: "Tests?" )
choice(name: 'b', choices:"NOnOKnMaybe", description: "Tests?" )
choice(name: 'c', choices:"NOnOKnMaybe", description: "Tests?" )
choice(name: 'd', choices:"NOnOKnMaybe", description: "Tests?" )
stages
stage("check params")
steps
script
//make some crazy validation
if ("$params.a" != "OK") ex("a")
if ("$params.b" != "OK") ex("b")
if ("$params.c" != "OK") ex("c")
if ("$params.d" != "OK") ex("d")
stage("Next stage")
steps
echo "Run"
thanks that was something i was looking for :)
– Onur Kadem
Aug 10 at 15:14
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You can use
when expression params.skipTests != "Yes",scriptblock in stage, orreturnsome variables and use it in next stages validation. Specify please, what You want to achieve.– 3sky
Aug 10 at 11:00