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.
Should this help ( on linux) :
head -5 /var/lib/jenkins/config.xml| grep -oP '(?<=<version>).*?(?=</version>)'
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With