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 de
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;
}
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
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