Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Jenkins version via java -jar jenkins.war --version without spam output

I'm trying to get the version of the Jenkins war deployed to /usr/share/jenkins/jenkins.war. I try running:

local version=$(java -jar /usr/share/jenkins/jenkins.war --version)

Unfortunately this prints several silly lines of output to stdout before the version number:

Running from: /usr/share/jenkins/jenkins.war
webroot: $user.home/.jenkins
1.643

Is there a way to tell Jenkins to avoid printing the webroot and "running from" lines? It's annoying and I imagine any attempt to parse it (check the 3rd line of stdout) is prone to breaking in the future.

like image 725
Kevin Burke Avatar asked Jan 04 '16 05:01

Kevin Burke


2 Answers

Should this help ( on linux) :

head -5  /var/lib/jenkins/config.xml| grep -oP '(?<=<version>).*?(?=</version>)'
like image 80
Alferd Nobel Avatar answered Sep 22 '22 15:09

Alferd Nobel


Since Jenkins 1.649, the --version flag causes the version to be printed out directly without any of the extraneous information:

$ wget -q http://mirrors.jenkins.io/war/1.649/jenkins.war \
      && java -jar jenkins.war --version
1.649

(original answer, pre-Jenkins 1.649)

As part of the WAR packaging process, the Jenkins version is written to the manifest, which is where the --version flag gets its answer from.

So while it may not be particularly pretty, this should be stable:

unzip -c /usr/share/jenkins/jenkins.war META-INF/MANIFEST.MF \
  | egrep ^Jenkins-Version: | awk '{print $2}' 

(assuming the availability of unzip and friends)

like image 28
Christopher Orr Avatar answered Sep 22 '22 15:09

Christopher Orr