Skip to content

Instantly share code, notes, and snippets.

@stchar
Last active October 13, 2023 10:43
Show Gist options
  • Save stchar/296226f438bbdf065e56c64108189a35 to your computer and use it in GitHub Desktop.
Save stchar/296226f438bbdf065e56c64108189a35 to your computer and use it in GitHub Desktop.
Jenkinsfile CLI shell wrapper
#!/bin/bash
# Jenkins-cli wrapper see. https://www.jenkins.io/doc/book/managing/cli/
#
# .installation:
# curl -o ~/bin/jcli-wrapper <gist_url>
# chmod +x ~/bin/jcli-wrapper
#
# .usage:
# jcli-wrapper Jenins-URL file-with-credentilas
#
# .example:
# jcli-wrapper https://jenkins.example.com $(realpath ~/.rcjenkins/jenkins) list-jobs
#
# .tip:
# you can create own wrapper with pre-defined values like:
# #file: ~/bin/jcli
# #!/bin/bash
# jcli-wrapper https://jenkins.example.com $(realpath ~/.rcjenkins/jenkins) $@
#
# .note:
# content of ~/.rcjenkins/jenkins is:
# {username}:{token|password}
# user:123456
jenkins_host=$1
shift 1
passwd_file=$1
shift 1
if [ ! -f ~/bin/jenkins-cli.jar ]
then
mkdir -p ~/bin
curl -o ~/bin/jenkins-cli.jar $jenkins_host/jnlpJars/jenkins-cli.jar
fi
java -jar ~/bin/jenkins-cli.jar -s ${jenkins_host} -webSocket -auth @${passwd_file} $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment