Changing the name and description of a Jenkins assembly through an API in JAVA

I am trying to modify the construction of Jenkins build # and build the description via the REST API using Java. I could see that in the below URL these guys tried to change the assembly description using some curl code,

Modify Jenkins description for assembly

I have no idea how he achieves this with the help of curious teams. Please, help!

http://localhost:8080/job/<BUILD_NAME>/<BUILD_NUMBER>/api/ 
0
source share
3 answers
 curl -u $USER:$PASSWORD --data-urlencode "description=$new_description" \ --data-urlencode "Submit=Submit" \ "$jenkins_url/job/$job_name/$build_number/submitDescription" 

It submits form data to "$jenkins_url/job/$job_name/$build_number/submitDescription"
Essentially, it emulates a user manually navigating to the assembly page by clicking the "Edit Description" link, entering a description, and clicking the "Submit" button. This is one way to do this.

You can also do this from CLI Jenkins.
Go to: http://localhost:8080/cli/command/set-build-description for reference.
If you have jenkins-cli.jar , you can run the following from the command line:

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

+1
source

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

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

FORM VALUES

+1
source

I needed to do this in Perl (for which I am new), and I had to work for the following:

 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; } 
+1
source

Source: https://habr.com/ru/post/982451/


All Articles