2

Is there any way to call jenkins job using jenkins-cli without passing the file parameter?

I have one jenkins job which accepts following parameter (key1,key2,file-parameter) Here is my jenins-cli call to the project.

java -jar jenkins-cli.jar \ 
        -s <url> build <jenkins-project> \
        -p key1=value1 -p FILE_PARAMETER=filename

Here if I don't pass key2 the build get triggered but i want to trigger the build without passing the file parameter.

If I do so am getting following error - No default value for the parameter FILE_PARAMETER.

Jayan
  • 18,003
  • 15
  • 89
  • 143
Manish Jindal
  • 293
  • 3
  • 11

1 Answers1

5

Jenkins exposes other protocols for remote execution such as http and ssh.

Given a job with two parameters

STRING_PARAMETER =String param
FILE_PARAMETER   =File upload param

here is a sample usage.

curl -X POST $JENKINS_URL/job/hello/build \
  --form file0=@my.txt \
  --form json='{"parameter": [{"name":"FILE_PARAMETER", "file":"file0"}, {"name":"STRING_PARAMETER","value":"A_VALUE_WITH_FILE"}]}'

and here with only string passed in. (file parameters skipped)

curl -X POST $JENKINS_URL/job/hello/build \
  --form file0=@my.txt \
  --form json='{"parameter": [ {"name":"STRING_PARAMETER","value":"NO_FILE_USED"}]}'
Jayan
  • 18,003
  • 15
  • 89
  • 143
  • It seems you can also do something like this: ssh jenkins.blah.com -p 59595 build PROJECT/NAME -p branch=master -p source_override.zip= < /dev/null And it will pull the file from the std_in where you can hit CTRL-D to send nothing or pipe from /dev/null. I can't fully answer the question for the ssh/jenkins-cli case yet. – poleguy Dec 06 '21 at 22:16
  • https://stackoverflow.com/questions/13348480/how-to-upload-file-from-command-line-as-file-parameter-in-jenkins – poleguy Dec 06 '21 at 22:19