Verigreen / verigreen

Verigreen is a lightweight, server side solution for verification of git commits. It is a gated check-in process which will not allow any failed CI commit to go into an integration/release/any protected branch. We keep it green (hence the name).
Apache License 2.0
57 stars 19 forks source link

Verigreen fails to get status for jenkins jobs if the 'jenkins.branchParamName' parameter is not the first parameter #130

Open aleitamar opened 6 years ago

aleitamar commented 6 years ago

When verigreen tries to get the status of jenkins jobs, it assumes that the first parameter of the job will be the 'jenkins.branchParamName' parameter. https://github.com/Verigreen/verigreen/blob/93e4efed4dd63e3c99a26785abad8e90d7fe1a89/verigreen-collector-impl/src/main/java/com/verigreen/collector/jobs/CallJenkinsJob.java#L211

If the first parameter is a different one, verigreen fails with 'TRIGGER_FAILED', even after triggering the jenkins job successfully.

This should be fixed or documented (maybe as part of the FAQ 'TRIGGER_FAILED' section?)

soninob commented 6 years ago

sounds like a bug, thank you! @borzamircea @AndreeaDora - have time to look at that? I guess we should call it by name

borzamircea commented 6 years ago

@soninob I think this could be fixed by getting hte parameter by key and not by index.

Something like:

JsonObject parameterJsonObject = (JsonObject) jsonParametersArray.get("branchParamName");
soninob commented 6 years ago

Thanks Mircea, care to supply a PR?

borzamircea commented 6 years ago

Will do in a couple of days once things are quieter.

borzamircea commented 6 years ago

Did some quick reading and the jsonArray only has get methods by index and not key: https://docs.oracle.com/javaee/7/api/javax/json/JsonArray.html

borzamircea commented 6 years ago

But apparently searching by key should do the trick.

https://stackoverflow.com/questions/42549545/get-value-by-key-jsonarray/42549752

borzamircea commented 6 years ago
JsonArray jsonParametersArray =  parameterJsonObjectArray.getAsJsonArray("parameters");

for(int i=0;i<jsonParametersArray.length();i++)
{
    JSONObject parameterJsonObject = jsonArray.getJSONObject(i);
    if (parameterJsonObject.keySet().contains("branchParamName"))
    {
        values.setBranchName(parameterJsonObject.get("branchParamName").getAsString());
        break;
    }
}

This should work.

soninob commented 6 years ago

good! Thank you, waiting for your PR :-)