Reputation: 65024
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.
Upvotes: 13
Views: 37390
Reputation: 1072
Extract your jankins.war file, it's generally located in your installation directory and navigate to the pom.xml file in META-INF\maven\org.jenkins-ci.main\jenkins-war. In this file, you'll find code similar to the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-war</artifactId>
<version>2.426.2</version>
<packaging>war</packaging>
<name>Jenkins war</name>
.....
The version is mentioned within the < version > tag. In my case, it's version 2.426.2.
Upvotes: 0
Reputation: 533
Jenkins version can be easily checked from the config.xml file.
Upvotes: 3
Reputation: 3979
Should this help ( on linux) :
head -5 /var/lib/jenkins/config.xml| grep -oP '(?<=<version>).*?(?=</version>)'
Upvotes: 6
Reputation: 111625
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)
Upvotes: 23