Changing Jenkins Build Name & Description through API in JAVA

前端 未结 3 981
北荒
北荒 2020-12-21 22:01

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

相关标签:
3条回答
  • 2020-12-21 22:37

    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;
    }
    
    0 讨论(0)
  • 2020-12-21 22:37
    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

    0 讨论(0)
  • 2020-12-21 22:48

    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

    0 讨论(0)
提交回复
热议问题