Skip to content

Instantly share code, notes, and snippets.

@icheko
Last active July 22, 2019 20:24
Show Gist options
  • Save icheko/a01efdceb69d46df9720b20568ba9616 to your computer and use it in GitHub Desktop.
Save icheko/a01efdceb69d46df9720b20568ba9616 to your computer and use it in GitHub Desktop.
function jenkins-runner(){
while test $# -gt 0; do
case "$1" in
-h|--help)
echo " "
echo "jenkins-runner [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-df specify docker run flags to include"
echo " example: -df ' -e TEST=VALUE -e TEST2=VALUE2'"
echo " "
echo "--bash bash into the container"
echo "--heroku-auth include HEROKU_AUTH_NETRC variable to properly mount the Heroku auth file"
return 0
;;
-df)
shift
if test $# -gt 0; then
local DOCKER_FLAGS=${1}
echo DOCKER_FLAGS: ${DOCKER_FLAGS}
fi
shift
;;
--heroku-auth)
shift
local HEROKU_AUTH_NETRC="-e HEROKU_AUTH_NETRC=$HOME/.netrc:/root/.netrc"
echo HEROKU_AUTH: ${HEROKU_AUTH_NETRC}
;;
--bash)
shift
local BASH_CMD="-it --entrypoint bash"
echo BASH_CMD: ${BASH_CMD}
;;
*)
local DOCKER_CMD=${1}
echo DOCKER_CMD
break
;;
esac
done
if [ ! -n "$BASH_CMD" ]; then
local DOCKER_CMD="--runHome /workspace/jenkins"
echo INCLUDING JENKINS FLAGS: ${DOCKER_CMD}
fi
echo
echo "Cleaning jenkins dir"
echo "-----------------------"
rm -Rfv jenkins/
mkdir -p jenkins
echo
docker run --rm --privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd):/workspace \
-e USER_HOME=$HOME \
-e USER_PWD=$PWD \
${DOCKER_FLAGS} \
${BASH_CMD} \
${HEROKU_AUTH_NETRC} \
ppiper/jenkinsfile-runner \
${DOCKER_CMD}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment