Skip to content

Instantly share code, notes, and snippets.

@teodorescuserban
Last active October 30, 2018 10:11
Show Gist options
  • Save teodorescuserban/7b2377077a31cdfd8502028f70d656bb to your computer and use it in GitHub Desktop.
Save teodorescuserban/7b2377077a31cdfd8502028f70d656bb to your computer and use it in GitHub Desktop.
jenkins: create PRs in the stack repos upon deployment.
# COMMIT_TO_REPO is a boolean parameter
# STACK is a choice parameter
if [ "${COMMIT_TO_REPO}" == "true" ]; then
# commit, push and create PR to the stack repo
REPONAME=XXX-stack
BRANCH=${STACK}-$(date +%Y%m%d-%H%M%S)
FILE_TO_COMMIT=$(readlink -f $PROJDIR/.env | sed "s|${BASEDIR}/${REPONAME}/||")
# don't care about possible wonky private files; we only care about that .env file
rsync -a ${BASEDIR}/${REPONAME} ${WORKSPACE}/ 2>/dev/null || echo -en ""
cd ${WORKSPACE}/${REPONAME}
git checkout -q -b ${BRANCH}
git diff-index --quiet HEAD ${FILE_TO_COMMIT}
if [ "$?" == "0" ]; then
echo -en "\nNo tag changes detected. Skip PR Creation.\n\n"
exit 0
fi
if [ "$?" != "1" ]; then
echo -en "\nAn error has occured. Failing the job.\n\n"
exit 1
fi
git commit -m "New ${SERVICE} deployment on ${STACK} stack, tag ${IMAGE_TAG}" -- ${FILE_TO_COMMIT}
echo -e "\n"
git push -u origin ${BRANCH}
echo -e "\nThe following PR has been created in ${REPONAME} stack repository:\n"
/usr/local/bin/hub pull-request -m "deployed ${SERVICE}:${IMAGE_TAG} on ${STACK}"
echo -e "\n"
# cleaning up workspace is left to post-build.
else
echo -en "\n\nSkip PR creation.\n\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment