From 6048195bd980a2e2b817af980e606590cfdd31f5 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Mon, 1 Aug 2016 20:15:16 +0200 Subject: [PATCH] Setup constraints for release For using constraints in the release pipeline, we need to setup the tree as follow: The project checked out needs to point to the tag and the requirements repo needs to point to the corresponding branch. Git does not easily give us the tag, especially since a tag could be on multiple branches. Implement some logic that gives us the oldest *stable* branch the tag is on and use that one. In case no *stable* branch is found, use master. The builder can be used in other pipelines as well since it checks explicitely for tags. Use this for now only for the {name}-tarball job. Change-Id: I806062dd24f9dbd2b98cafd32c08bb524e73c5ac --- jenkins/jobs/macros.yaml | 63 +++++++++++++++++++++++++++++++++++ jenkins/jobs/python-jobs.yaml | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/jenkins/jobs/macros.yaml b/jenkins/jobs/macros.yaml index 9974c2fe60..57dbbd85a6 100644 --- a/jenkins/jobs/macros.yaml +++ b/jenkins/jobs/macros.yaml @@ -184,6 +184,69 @@ /usr/zuul-env/bin/zuul-cloner -m $CLONEMAP --cache-dir /opt/git \ $BRANCH_ARG git://git.openstack.org $ZUUL_PROJECT +- builder: + # Use this macro in the release pipeline to get a tagged repo with + # tag checked out and requirements repo with the branch the tag is + # on. + # The macro also works in other pipelines. + name: zuul-release-git-prep-upper-constraints + builders: + - shell: | + #!/bin/bash -xe + function get_branch_tag { + + BRANCHES=`git branch -a --contains $ZUUL_REFNAME` + + TARGET_BRANCH=`echo "$BRANCHES"|grep '^ remotes/origin/stable'|cut -d/ -f3-|sort|head -n1` + + if [ -z $TARGET_BRANCH ] ; then + TARGET_BRANCH=`echo "$BRANCHES"|grep '^ remotes/origin/'|cut -d/ -f3-|sort|grep -v ^HEAD|head -n1` + fi + # Nothing found. + # Note that zuul-cloner will also fallback to master if + # the TARGET_BRANCH does not exist. + if [ -z $TARGET_BRANCH ] ; then + echo "Tag not found, falling back to master" + TARGET_BRANCH=master + fi + } + + CLONEMAP=`mktemp` + REQS_DIR=`mktemp -d` + function cleanup { + mkdir -p $WORKSPACE + rm -rf $CLONEMAP $REQS_DIR + } + trap cleanup EXIT + cat > $CLONEMAP << EOF + clonemap: + - name: $ZUUL_PROJECT + dest: . + EOF + + /usr/zuul-env/bin/zuul-cloner -m $CLONEMAP --cache-dir /opt/git \ + git://git.openstack.org $ZUUL_PROJECT + + if [[ "$ZUUL_PROJECT" != "openstack/requirements" ]]; then + # Figure out branch for requirements checkout + if [[ "$ZUUL_REFNAME" =~ ^refs/tags/ ]] ; then + get_branch_tag + else + TARGET_BRANCH=$ZUUL_REFNAME + fi + + cat > $CLONEMAP << EOF + clonemap: + - name: openstack/requirements + dest: $REQS_DIR + EOF + /usr/zuul-env/bin/zuul-cloner -m $CLONEMAP --cache-dir /opt/git \ + --branch $TARGET_BRANCH \ + git://git.openstack.org openstack/requirements + cp $REQS_DIR/upper-constraints.txt ./ + fi + + - builder: name: branch-git-prep builders: diff --git a/jenkins/jobs/python-jobs.yaml b/jenkins/jobs/python-jobs.yaml index c2c5b53818..ad59277223 100644 --- a/jenkins/jobs/python-jobs.yaml +++ b/jenkins/jobs/python-jobs.yaml @@ -560,7 +560,7 @@ builders: - print-template-name: template-name: "{template-name}" - - gerrit-git-prep + - zuul-release-git-prep-upper-constraints - install-distro-packages - revoke-sudo - tarball: