Home > Software engineering >  How can i send values to a Jenkins script?
How can i send values to a Jenkins script?

Time:08-04

I have a Jenkins job and in that job the first thing that runs is a powershell script that I want to capture user inputs values and set them as global variables that are used through out the Jenkins job. Now i want the user to be able to put these values in from their machine and then run the job with these values ?

How can i do this ?

CodePudding user response:

You need to check the This project is parameterized checkbox in the settings of your job in Jenkins. Then define the name, type etc.

The given name is already accessible via standard syntax. In shell script ${nameOfParam} or %nameOfParam (depending on your shell / os). In pipelines they are also accessible via params.nameOfParam.

You can set these variables via GUI using Build with parameters or via API call http://<JENKINS_URL>/job/<JOB_NAME>/buildWithParameters/nameOfParam=foo

See also: https://www.baeldung.com/ops/jenkins-parameterized-builds

Only thing I quiet don't get from your question is, what you exactly want to do with the powershell script. A pipeline script in Jenkins is executed on a node, so if the job starts it should be running without any user interaction. To set values from the user input as global variables in a powershell script, you already need to have them available within the jenkins node, hence it's nonsense to set them in the powershell script because they are already available.

  • Related