Skip to content

Commit

Permalink
Support storing version in gradle.properties
Browse files Browse the repository at this point in the history
This will now auto-increment the patch version if the Jenkins version
does not change.
  • Loading branch information
samrocketman committed Aug 17, 2018
1 parent fd3d711 commit 1957189
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ apply from: "${bootstrapHome}/shared.gradle"
//version should be the jenkins.war version appended by .1 and increments .1
//every time there's non-jenkins.war version changes to the package.
//if upgrading jenkins.war version then it should be reset to .1.
version = '2.121.1.1'
description = "Built from ${tokens['PACKAGENAME']} @ ${tokens['COMMIT']}"

//Jenkins war and plugin versions
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bootstrapHome=.
version=2.121.1.1
1 change: 1 addition & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export SED
)

echo 'bootstrapHome=jenkins-bootstrap-shared' > gradle.properties
grep -- '^version' jenkins-bootstrap-shared/gradle.properties >> gradle.properties
cat > jenkins_bootstrap.sh <<'EOF'
#!/bin/bash
source jenkins-bootstrap-shared/jenkins_bootstrap.sh
Expand Down
7 changes: 4 additions & 3 deletions scripts/upgrade/generateSedExpr.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

import jenkins.model.Jenkins

//update build.grade package version string
//update build.gradle package version string
println "s/^(version ?= ?)'[^']+'(.*)\$/\\1'${Jenkins.instance.version}.1'\\2/"
//update jenkins.war version in build.gradle
println "s/^(version)=.*\$/\\1=${Jenkins.instance.version}.1/"
//update jenkins.war version in dependencies.gradle
println "s/(.*getjenkins.*:jenkins-war):[^@]+@(war')/\\1:${Jenkins.instance.version}@\\2/"

//update all plugins in build.gradle
//update all plugins in dependencies.gradle
Jenkins.instance.pluginManager.plugins.each { p ->
println "s/(.*getplugins.*:${p.shortName}):[^@]+@(hpi')/\\1:${p.version}@\\2/"
}
Expand Down
9 changes: 7 additions & 2 deletions scripts/upgrade/remote_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ CUSTOM_TMPFILE="${TMP_DIR}/custom"
echo 'Upgrade build.gradle file.'
export JENKINS_CALL_ARGS="-m POST ${JENKINS_WEB}/scriptText --data-string script= -d"
"${SCRIPT_LIBRARY_PATH}"/jenkins-call-url "${SCRIPT_LIBRARY_PATH}"/upgrade/generateSedExpr.groovy > "${TMPFILE}"
"${SED[@]}" -i.bak -f "${TMPFILE}" build.gradle
rm build.gradle.bak
if [ -n "${USE_GRADLE_PROPERTIES:-}" ]; then
VERSION_FILE=gradle.properties
else
VERSION_FILE=build.gradle
fi
"${SED[@]}" -i.bak -f "${TMPFILE}" "${VERSION_FILE}"
rm "${VERSION_FILE}.bak"

#generate a new dependencies.gradle file
echo 'Upgrade dependencies.gradle file.'
Expand Down
34 changes: 34 additions & 0 deletions scripts/upgrade/upgrade_build_gradle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,39 @@ if [ -z "${NO_UPGRADE}" -a "$("${SCRIPT_LIBRARY_PATH}"/jenkins-call-url "${SCRIP
source "${SCRIPT_LIBRARY_PATH}"/upgrade/env.sh
fi

if grep -- '^version' gradle.properties; then
export USE_GRADLE_PROPERTIES=1
fi

function get_version() {
awk 'BEGIN { FS="=" }; $1 == "version" { print $2 }' < gradle.properties
}

if [ -n "${USE_GRADLE_PROPERTIES:-}" ]; then
VERSION="$(get_version)"
# increment the patch
VERSION="${VERSION%.*}.$(( ${VERSION##*.} + 1 ))"
fi

#write jenkins master and plugin versions to build.gradle and dependencies.gradle
"${SCRIPT_LIBRARY_PATH}"/upgrade/remote_dependencies.sh

# GNU or BSD sed is required. Homebrew on Mac installs GNU sed as gsed.
# Try to detect gsed; otherwise, fall back to detecting OS for using sed.
SED=()
if type -P gsed &> /dev/null; then
SED=(gsed -r)
elif [ "$(uname -s)" = "Darwin" ] || uname -s | grep -- 'BSD$' &> /dev/null; then
SED=(sed -E)
else
# assume Linux GNU sed
SED=(sed -r)
fi

if [ -n "${USE_GRADLE_PROPERTIES:-}" ]; then
NEW_VERSION="$(get_version)"
if [ "${NEW_VERSION%.*}" = "${VERSION%.*}" ]; then
"${SED[@]}" -i.bak -- "s/^(version)=.*/\\1=${VERSION}/" gradle.properties
rm gradle.properties.bak
fi
fi

0 comments on commit 1957189

Please sign in to comment.