Jenkins CLI
Jenkins provides a JAR file that can be used to connect to Jenkins and execute common tasks. You will require a Jenkins API token generated from https://jenkins.mapsandbox.net/user/<your Jenkins username>/security/
More information on the Jenkins CLI is available here.
Installation
-
Open a Terminal window:
-
Download the Jenkins CLI JAR:
curl -O https://jenkins.mapsandbox.net/jnlpJars/jenkins-cli.jar
-
Open your .zshrc and add:
export JENKINS_API_TOKEN="<provided Jenkins token>"
export JENKINS_API_USER=<provided Jenkins user>
export JENKINS_API_URL="https://jenkins.mapsandbox.net"
-
source ~/.zshrc
Usage
| The -s flag will cause the command to wait until the completion/abortion of the command. This is useful when you want to wait to know if a build was successful or not. |
-
Start a build of main for callback-service:
java -jar jenkins-cli.jar -s $JENKINS_API_URL -auth $JENKINS_API_USER:$JENKINS_API_TOKEN build callback-service/main -s
-
Start a build of branch for callback-service:
java -jar jenkins-cli.jar -s $JENKINS_API_URL -auth $JENKINS_API_USER:$JENKINS_API_TOKEN build callback-service/<branch name> -s
-
View logs for main:
java -jar jenkins-cli.jar -s $JENKINS_API_URL -auth $JENKINS_API_USER:$JENKINS_API_TOKEN console callback-service/main