1

I am trying to change the Jenkins's build # and build description through REST API using Java. I could see that in the below URL, this guys has tried to change the build description using some curl code,

Modifying Jenkins Description for a build

I have no idea how he is achieving it through curl commands. Please help!

http://localhost:8080/job/<BUILD_NAME>/<BUILD_NUMBER>/api/
Community
  • 1
  • 1
JavaLover
  • 73
  • 2
  • 14

3 Answers3

4
curl -u $USER:$PASSWORD   --data-urlencode "description=$new_description" \
--data-urlencode "Submit=Submit" \
"$jenkins_url/job/$job_name/$build_number/submitDescription"

He is submitting webpage form data to "$jenkins_url/job/$job_name/$build_number/submitDescription"
Essentially he is emulating a user manually going to the build page, clicking "Edit Description" link, entering description and clicking "Submit" button. That's one way of doing it.

You can also do it from the Jenkins CLI.
Go to: http://localhost:8080/cli/command/set-build-description for help.
Once you have jenkins-cli.jar you can execute the following from the command line:

java -jar jenkins-cli.jar -s http://localhost:8080/ set-build-description <BUILD_NAME> <BUILD_NUMBER> YOUR-DESCRIPTION

Slav
  • 27,057
  • 11
  • 80
  • 104
  • 1
    Hi Slav, I appreciate your effort on this. I basically wanted to do REST API service call to Jenkins as I mentioned http://localhost:8080/job///api/ but through the CLI. Could you kindly re-consider ? – JavaLover Aug 21 '14 at 15:12
  • I can see that `/submitDescription` works if I replay the browser request using cookie auth, but in my script if I switch to BASIC auth then I get a 403 – Carl Walsh Jun 14 '23 at 23:57
3

I needed to do this in Perl (which I'm new to) and got the following to work for me:

sub ChangeJobDescription {
    my $url = 'http://jenkinurl/job/<job_name>/<job_number>/configSubmit';
    my $jsonData = '{"displayName" => "<new Build title>", "description" => "<new Build description>"}';
    my $ua = LWP::UserAgent->new();
    my $req = POST($url,
        Content_Type => 'application/x-www-form-urlencoded',
            Content => [ 'Submit' => 'save', 'json' => $jsonData    ],
    );
    $req->authorization_basic('user', 'password');
    my $response = $ua->request($req);
    print $response->as_string;
}
Dave Michener
  • 1,058
  • 11
  • 30
1

I was able to make a POST call using the following URL and "Content-Type" header as application/x-www-form-urlencoded in Payload.

URL: http://<jenkins>:8058/job/MYJOB_NAME/BUILD_NUMBER/configSubmit

FORM VALUES

CSchulz
  • 10,882
  • 11
  • 60
  • 114
JavaLover
  • 73
  • 2
  • 14