public ArrayList<Tag> getBuildTags(int buildNr, String jobName){
ArrayList<Tag> tags = new ArrayList<Tag>();
try {
String requestString;
String jenkinsUrl = Jenkins.getInstance().getRootUrl();
String encodedJobName = java.net.URLEncoder.encode(jobName, "UTF-8").replace("+", "%20");
String metadataApiRequest = "metadata-httpcli/get?job=" + encodedJobName + "&build=" + buildNr;
requestString = jenkinsUrl + metadataApiRequest;
URL url = new URL(requestString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
if(connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer resultString = new StringBuffer();
String response;
while ((response = rd.readLine()) != null) {
resultString.append(response);
}
rd.close();
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(resultString.toString());
for (int i = 0; i < jsonArray.size(); i++) {
String name = jsonArray.getJSONObject(i).get("name").toString();
switch (name) {
//Hide metadata-plugin predefined tags
case "job-info":
break;
case "build":
break;
default:
String value = jsonArray.getJSONObject(i).get("value").toString();
tags.add(new Tag(name.toUpperCase(), value.toLowerCase()));
break;
}
}
}
connection.disconnect();
}catch (IOException e){
e.printStackTrace();
}
return tags;
}
I'm on mobile right now so I can't check but I'm pretty sure that plugin like most others will have actions (getActions()) attached to the build. Nothing exposed by rest should be hidden from native interfaces.
If you are just writing a script, it belongs on the users list, but you'll need to create/reuse an existing user. All users will have username and API tokens on thier edit profile page, you should be able to use that to basic authenticate for APIs.
Gavin
MetadataBuildAction metadataBuild = Jenkins.getInstance().getItemByFullName(jobName, Job.class).getBuildByNumber(buildNr).getAction(MetadataBuildAction.class);
if(metadataBuild != null) {
Collection<String> metadataNames = metadataBuild.getChildNames();
stage 'testMetadata'node{
def testJob = currentBuild; properties([[$class :'MetadataJobProperty', values : [[ $class: 'StringMetadataValue', name : 'owner', value : 'bob' ]] ]]);}To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/d8306864-e156-425e-962b-3467dad93f23%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.