简体   繁体   English

通过JAVA中的API更改Jenkins构建名称和描述

[英]Changing Jenkins Build Name & Description through API in JAVA

I am trying to change the Jenkins's build # and build description through REST API using Java. 我正在尝试通过使用Java的REST API更改Jenkins的build#和build描述。 I could see that in the below URL, this guys has tried to change the build description using some curl code, 我可以在下面的URL中看到,这些人试图使用一些curl代码来更改构建说明,

Modifying Jenkins Description for a build 修改构建的Jenkins描述

I have no idea how he is achieving it through curl commands. 我不知道他是如何通过curl命令实现它的。 Please help! 请帮忙!

http://localhost:8080/job/<BUILD_NAME>/<BUILD_NUMBER>/api/

I needed to do this in Perl (which I'm new to) and got the following to work for me: 我需要在Perl(这是我的新手)中进行此操作,并为我提供了以下工作:

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" 他正在将网页表单数据提交到"$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. 您也可以从Jenkins CLI执行此操作。
Go to: http://localhost:8080/cli/command/set-build-description for help. 转到: http://localhost:8080/cli/command/set-build-description以获得帮助。
Once you have jenkins-cli.jar you can execute the following from the command line: 有了jenkins-cli.jar您可以jenkins-cli.jar执行以下命令:

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和“ Content-Type”标头作为Payload中的application / x-www-form-urlencoded进行POST调用。

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

表格值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM