Skip to content

Commit

Permalink
Merge pull request #427 from carlossg/daily
Browse files Browse the repository at this point in the history
[INFRA-729] Publish all our versions under jenkinsci docker org
  • Loading branch information
R. Tyler Croy authored Feb 6, 2017
2 parents 29da76e + 0f763d4 commit 1bf552c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ node('docker') {

if (infra.isTrusted()) {
stage('Publish') {
sh './weekly.sh'
sh './publish.sh'
}
}
}
70 changes: 70 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash -eu

# Publish any versions of the docker image not yet pushed to jenkinsci/jenkins

set -o pipefail

sort-versions() {
if [ "$(uname)" == 'Darwin' ]; then
gsort --version-sort
else
sort --version-sort
fi
}

# Try tagging with and without -f to support all versions of docker
docker-tag() {
local from="jenkinsci/jenkins:$1"
local to="jenkinsci/jenkins:$2"
local out
if out=$(docker tag -f "$from" "$to" 2>&1); then
echo "$out"
else
docker tag "$from" "$to"
fi
}

get-published-versions() {
curl -q -fsSL https://registry.hub.docker.com/v1/repositories/jenkinsci/jenkins/tags | egrep -o '"name": "[0-9\.]+"' | egrep -o '[0-9\.]+'
}

get-latest-versions() {
curl -q -fsSL https://api.github.com/repos/jenkinsci/jenkins/tags?per_page=20 | grep '"name": "jenkins-' | egrep -o '[0-9]+(\.[0-9]+)+' | sort-versions | uniq
}

publish() {
local version=$1
local sha
local build_opts="--no-cache --pull"

sha=$(curl -q -fsSL "http://repo.jenkins-ci.org/simple/releases/org/jenkins-ci/main/jenkins-war/${version}/jenkins-war-${version}.war.sha1")

docker build --build-arg "version=$version" \
--build-arg "sha=$sha" \
--tag "jenkinsci/jenkins:$version" ${build_opts} .

docker-tag $version latest

docker push "jenkinsci/jenkins:$version"
docker push "jenkinsci/jenkins:latest"

# Update lts tag
if [ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]; then
echo "Updating lts tag to $version"
docker-tag $version lts
docker push "jenkinsci/jenkins:lts"
fi
}

published_versions="$(get-published-versions)"

for version in $(get-latest-versions); do
if echo "${published_versions}" | grep -q "^${version}$"; then
echo "Version is already published: $version"
else
echo "Publishing version: $version"
publish $version
fi
done


22 changes: 0 additions & 22 deletions weekly.sh

This file was deleted.

0 comments on commit 1bf552c

Please sign in to comment.