Skip to content

Instantly share code, notes, and snippets.

@arilivigni
Created January 15, 2019 19:18
Show Gist options
  • Save arilivigni/e0c6d58b4abbc68535c529dbc1f58dad to your computer and use it in GitHub Desktop.
Save arilivigni/e0c6d58b4abbc68535c529dbc1f58dad to your computer and use it in GitHub Desktop.
Jenkinsfile-runner example
#!/bin/bash
set -x
set -e
# Clone the repo
git clone https://github.com/jenkinsci/jenkinsfile-runner.git
pushd jenkinsfile-runner
# Build jenkinsfile runner if it doesn't exist
if [[ ! -d $PWD/app/bin ]];then
mvn package
fi
# Setup Jenkins plugins and environment
export JENKINS_BASE=$PWD/tmp
export JENKINS_HOME=$JENKINS_BASE/jenkins_home
export REF=$JENKINS_BASE/plugins
export JENKINS_UC_DOWNLOAD="http://mirrors.jenkins-ci.org"
mkdir -p $JENKINS_BASE
[[ -e tmp/jenkins.war ]] || { echo -n "Getting lts jenkins.war: "; curl -s -L -f http://mirrors.jenkins.io/war-stable/latest/jenkins.war -o $JENKINS_BASE/jenkins.war; echo "done" ;}
echo -n "Getting base-plugins.txt"
#curl -L -f -s https://raw.githubusercontent.com/fabric8io/openshift-jenkins-s2i-config/master/plugins.txt -o $JENKINS_BASE/base-plugins.txt
curl -L -f -s https://raw.githubusercontent.com/openshift/jenkins/master/2/contrib/openshift/base-plugins.txt -o $JENKINS_BASE/base-plugins.txt
curl -L -f -s https://raw.githubusercontent.com/openshift/jenkins/master/2/contrib/jenkins/install-plugins.sh -o $JENKINS_BASE/install-plugins.sh
echo done
if [[ ! -d $JENKINS_HOME ]];then
mkdir -p $JENKINS_HOME
pushd $JENKINS_HOME >/dev/null && {
unzip $JENKINS_BASE/jenkins.war
} && popd >/dev/null
fi
bash $JENKINS_BASE/install-plugins.sh $JENKINS_BASE/base-plugins.txt
# Generic Jenkinsfile
cat <<EOF > $JENKINS_BASE/Jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Hello world!'
sh 'ls -la'
}
}
}
}
EOF
# Run a Jenkins pipeline
$PWD/app/target/appassembler/bin/jenkinsfile-runner -w $PWD/tmp/jenkins_home -p $PWD/tmp/plugins/ -f $PWD/tmp/
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment