Created
August 8, 2017 02:56
-
-
Save elleryq/e5bd76c3019e7ed066e997dd2faa30a2 to your computer and use it in GitHub Desktop.
Upgrade jenkins plugins via random SSH Port. You have to enable random SSHD port in Jenkins security settings.
This file contains hidden or 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
| #!/bin/bash | |
| JENKINS_HOST=jenkins_host | |
| BASE_URL=http://${JENKINS_HOST}/jenkins/ | |
| SSH_ENDPOINT=$(curl -Lv ${BASE_URL}login 2>&1 | grep 'X-SSH-Endpoint') | |
| USER=$(whoami) | |
| echo "${SSH_ENDPOINT}" | |
| PORT=$(echo "${SSH_ENDPOINT}" | awk -F: '{printf("%d", $3);}' | tr -d "\n") | |
| echo "port=${PORT}" | |
| echo "user=${USER}" | |
| echo "host=${JENKINS_HOST}" | |
| # ssh -l ${USER} -p ${PORT} ${JENKINS_HOST} help | |
| UPDATE_LIST=$(ssh -l ${USER} -p ${PORT} ${JENKINS_HOST} list-plugins | grep -e ')$' | awk '{ print $1 }') | |
| if [ ! -z "${UPDATE_LIST}" ]; then | |
| echo Updating Jenkins Plugins: ${UPDATE_LIST}; | |
| ssh -l ${USER} -p ${PORT} ${JENKINS_HOST} install-plugin ${UPDATE_LIST}; | |
| ssh -l ${USER} -p ${PORT} ${JENKINS_HOST} safe-restart; | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment