score:1

Accepted answer

you may trace successful and failed jenkins builds from git commits to associated ca agilecentral (rally) artifacts by using git connector and jenkins plugin as long as both point to the same repository, and a commit in git mentions formattedid of related artifact.

here is a java example based on rally api toolkit for java. regardless of the choice of toolkit, language, etc. it is the underlying ws api object model that provides access to this data. i limited build query by creationdate. among other fields on build object i fetch changesets collection. each element of that collection is a reference to a changeset object. git connector creates changesets objects in ca agile central(rally). each changeset object has artfacts collection field and changes collection field. each element of artifacts collection is a reference to rally artifact, e.g. user story, defect. by fetching pathandfilename on each change object you get the associated source file. now we can trace a failed build to a specific commit, file, and user story.

this is a screenshot from the console output created by java code below. eventually you may want to present data it a more visually appealing way. this example only shows that builds and commits can be traced to user stories or defects via ws api.

separate requests are often needed to hydrate collections in ws api. since build and cangesets data can be large, binding those queries by some criteria, e.g. creationdate will make it faster.

enter image description here

public class getbuilddata {

    public static void main(string[] args) throws exception {

        string host = "https://rally1.rallydev.com";
        string apikey = "_abc123"; 
        string applicationname = "nickm:getbuilddata";
        string workspaceref = "/workspace/12345";
        string projectref = "/project/1346";

        rallyrestapi restapi = null;
        try {
            string datestring = "2016-05-12";
            restapi = new rallyrestapi(new uri(host),apikey);
            restapi.setapplicationname(applicationname);
            queryrequest buildrequest = new queryrequest("build");
            buildrequest.setfetch(new fetch("status,message,start,uri,changesets"));
            buildrequest.setqueryfilter(new queryfilter("creationdate", ">", datestring));
            buildrequest.setworkspace(workspaceref);
            buildrequest.setproject(projectref);
            queryresponse buildresponse = restapi.query(buildrequest);
            for (int i=0; i<buildresponse.gettotalresultcount();i++){
                jsonobject buildobj = buildresponse.getresults().get(i).getasjsonobject();
                system.out.println("build status: " + buildobj.get("status") +
                        "\n build message: " + buildobj.get("message") +
                        "\n build start:   " + buildobj.get("start") +
                        "\n build uri:     " + buildobj.get("uri"));
                jsonobject changesetscollection = buildobj.get("changesets").getasjsonobject();
                queryrequest changesetsrequest = new queryrequest(changesetscollection);
                changesetsrequest.setfetch(new fetch("artifacts","changes", "revision"));
                changesetsrequest.setlimit(1000);
                queryresponse changesetsresponse = restapi.query(changesetsrequest);
                for (int j=0; j<changesetsresponse.gettotalresultcount();j++) {
                    jsonobject changesetobj = changesetsresponse.getresults().get(j).getasjsonobject();
                    system.out.println("\nchangeset revision: " + changesetobj.get("revision"));
                    jsonobject artifactscollection = changesetobj.get("artifacts").getasjsonobject();
                    queryrequest artifactsrequest = new queryrequest(artifactscollection);
                    artifactsrequest.setfetch(new fetch("formattedid"));
                    queryresponse artifactsresponse = restapi.query(artifactsrequest);
                    for (int k=0; k<artifactsresponse.gettotalresultcount();k++) {
                        jsonobject artifactobj = artifactsresponse.getresults().get(k).getasjsonobject();
                        system.out.println("\nartifact formattedid: " + artifactobj.get("formattedid"));
                    }
                    jsonobject changescollection = changesetobj.get("changes").getasjsonobject();
                    queryrequest changesrequest = new queryrequest(changescollection);
                    changesrequest.setworkspace(workspaceref);
                    changesrequest.setproject(projectref);
                    changesrequest.setfetch(new fetch("pathandfilename"));
                    queryresponse changesresponse = restapi.query(changesrequest);
                    for (int l=0; l<changesresponse.gettotalresultcount();l++) {
                        jsonobject changeobj = changesresponse.getresults().get(l).getasjsonobject();
                        system.out.println("change pathandfilename: " + changeobj.get("pathandfilename"));
                    }

                }
                system.out.println("--------------------------------");
            }
        } finally {
            if (restapi != null) {
                restapi.close();
            }
        }
    }
}

if you want to display build data inside agile central (rally) appsdk2.1 javascript app can be deployed in a custom page. here is quick example to start with:

    <!doctype html>
<html>
<head>
    <title>builds by date</title>
    <script type="text/javascript" src="/apps/2.1/sdk.js"></script>
    <script type="text/javascript">
        rally.onready(function () {
                ext.define('customapp', {
    extend: 'rally.app.app',
    componentcls: 'app',
    launch: function() {
        this.add({
            xtype: 'component',
            itemid: 'datepick',
            html: 'pick a date:',
            width: 100,
            margin: 10
        },
        {
            xtype: 'rallydatepicker',
            showtoday: false,
            contentel: ext.componentquery.query('#datepick')[0],
            margin: 10,
            handler: function(picker, date) {
                this.getbuilds(date);
            },
            scope:this
        },
        {
            xtype: 'container',
            itemid: 'gridcontainer'
        });
    },
    getbuilds:function(date){
        var formatteddate = rally.util.datetime.formatwithdefault(date, this.getcontext());
        ext.componentquery.query('#datepick')[0].update((formatteddate) + '<br /> selected');
        if (this.down('rallygrid')) {
            ext.componentquery.query('#gridcontainer')[0].remove(ext.componentquery.query('#buildsgrid')[0], true);
        }
        this.down('#gridcontainer').add({
            xtype: 'rallygrid',
            itemid: 'buildsgrid',
            columncfgs: [
                'status',
                'message',
                'start',
                'uri',
                'changesets'
            ],
            storeconfig: {
                model: 'build',
                filters:[
                    {
                        property: 'creationdate',
                        operator: '>=',
                        value: rally.util.datetime.toisostring(date,true)
                    }
                ]
            }
        });
    }
});
            rally.launchapp('customapp', {
                name:"builds by date",
                parentrepos:""
            });
        });
    </script>
    <style type="text/css">
        .app {
  /* add app styles here */
}
    </style>
</head>
<body>
</body>
</html>

enter image description here

score:1

if you append /api/json?pretty=true to the end of your job's url in jenkins you can see a json output of the job itself, which can lead you to the latest build number. further, that will lead you to the url of the most recent build, which (again appending /api/json?pretty=true) can lead you to a json list of changesets (and corresponding commit messages).

you might not even need to tap into rally! :-)

you can consume that json from your spring application using json marshaling and the resttemplate spring class.


Related Query

More Query from same tag