How to execute locally Jenkinsfile
- Install a local Jenkins (avoid Docker to avoid to have port mapping, volume and other issues)
- https://jenkins.io/download/ -> get the war file
- Start Jenkins:
wget [jenkins.war]
mkdir jenkins_home
JENKINS_HOME=$PWD/jenkins_home java -jar jenkins.war
- Open
localhost:8080
in chrome - Enter the temporary key / password
- Do not install any plugin
- Go to Manage Jenkins / plugins / proxy: setup the web proxy
- Install
pipeline
andGIT
plugin - Get Jenkins CLI:
curl -OL http://localhost:8080/jnlpJars/jenkins-cli.jar
cd ~
mkdir jenkinsfile-dev
cd jenkinsfile-dev
git init
echo jenkins_home > .gitigore
echo jenkins.war >> .gitignore
git add .gitignore
git commit -m "Initial commit"
Edit Jenkinsfile:
pipeline {
agent any
stages {
stage ("Do It") {
steps { echo "testing" }
}
}
}
The repository is local (it does not have to be on GitHub). So, all the changes in Jenkinsfile are local and avoid a round trip.
We create a small script which
- Job type: pipeline or multibranch pipeline
- In the Pipeline section:
pipeline script from SCM
- Repository URL:
file:///tmp/jenkinsfile-dev
- Repository URL:
#!/bin/bash
git diff --quiet || git commit -am "x"
java -jar jenkins-cli.jar -s http://localhost:8080 \
- auth admin:admin -http -noKeyAuth \
build -s -v jenkinsfile-nightmare-demo
Now, let's get rid of X
intermediary commits.
git rebase -i [commit hash]
for each X line, use f
(fixup)
git commit --amend
git rebase --continue