更改詹金斯版本名称&通过JAVA中的API进行描述
问题描述:
我正在尝试使用Java通过REST API更改Jenkins的内部版本号和内部版本说明.我可以在下面的URL中看到,这些人试图使用一些curl代码来更改构建说明,
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,
我不知道他是如何通过curl命令实现它的.请帮忙!
I have no idea how he is achieving it through curl commands. Please help!
http://localhost:8080/job/<BUILD_NAME>/<BUILD_NUMBER>/api/
答
我需要在Perl(这是我的新手)中进行此操作,并为我提供了以下工作:
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;
}