Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@takeshin's answer is fine if you have access to the build.xml file, but this may break, especially if you are building on a slave node (since the slave does not have the referenced build.xml).</p> <p>Fear not, since you can access this information via Jenkins directly, using its remote access api:</p> <p><a href="https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API" rel="noreferrer">https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API</a></p> <p>For example:</p> <pre><code>http://&lt;host&gt;/jenkins/job/&lt;job_name&gt;/lastSuccessfulBuild/api/xml </code></pre> <p>(will give you the xml content... you could replace xml with json to get json content back instead of XML, for example).</p> <p>NOTE that you may need to use authentication if you've setup your Jenkins instance to require it. Again, fear not: <a href="https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients" rel="noreferrer">https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients</a></p> <p>Then it's a simple matter of parsing the XML for what you want. Something like this, perhaps:</p> <pre><code>curl --silent --user $USER:$API_TOKEN $URL | grep "&lt;lastBuiltRevision&gt;" | sed 's|.*&lt;lastBuiltRevision&gt;.*&lt;SHA1&gt;\(.*\)&lt;/SHA1&gt;.*&lt;branch&gt;.*|\1|' </code></pre> <p>So, pulling it all together, you can end up with a (relatively) simple shell script to retrieve the last good revision hash from Jenkins:</p> <pre><code>#!/bin/sh GIT_LOG_FORMAT="%ai %an: %s" USER=&lt;username&gt; API_TOKEN=&lt;api_token&gt; LAST_SUCCESS_URL_SUFFIX="lastSuccessfulBuild/api/xml" #JOB_URL gets populated by Jenkins as part of the build environment URL="$JOB_URL$LAST_SUCCESS_URL_SUFFIX" LAST_SUCCESS_REV=$(curl --silent --user $USER:$API_TOKEN $URL | grep "&lt;lastBuiltRevision&gt;" | sed 's|.*&lt;lastBuiltRevision&gt;.*&lt;SHA1&gt;\(.*\)&lt;/SHA1&gt;.*&lt;branch&gt;.*|\1|') # Pulls all commit comments since the last successfully built revision LOG=$(git log --pretty="$GIT_LOG_FORMAT" $LAST_SUCCESS_REV..HEAD) echo $LOG </code></pre> <p>Cheers,</p> <p>Levi</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload