Created
June 5, 2015 18:40
-
-
Save stisti/a33c624288fde9cb418e to your computer and use it in GitHub Desktop.
Jenkins jobname completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jenkins_jobnames() { | |
node -e 'require("request")({url: process.env.JENKINS_URL+"/view/All/api/json", strictSSL: false},function(e,r,b){JSON.parse(b).jobs.forEach(function(e){console.log(e.name)})})' | |
} | |
# Alternative implementation | |
jenkins_jobnames2() { | |
http $JENKINS_URL/api/json | jq -r .jobs[].name | |
} | |
__jenkins_jobname_complete() { | |
cmd="$1" | |
word_being_completed="$2" | |
word_before="$3" | |
( | |
# Does cache file exist and is it less than 1 hour old? | |
if [ -s $HOME/.jenkins_jobnames ]; then | |
eval $(stat -s $HOME/.jenkins_jobnames) | |
if [ $(($(date +%s) - $st_mtime)) -lt 3600 ]; then | |
cat $HOME/.jenkins_jobnames | |
else | |
jenkins_jobnames | tee $HOME/.jenkins_jobnames | |
fi | |
else | |
jenkins_jobnames | tee $HOME/.jenkins_jobnames | |
fi | |
) | egrep "^${word_being_completed}" | |
} | |
type -p nestor >/dev/null && complete -C __jenkins_jobname_complete nestor | |
type -p j >/dev/null && complete -C __jenkins_jobname_complete j |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment