Created
July 3, 2018 14:34
-
-
Save yogeek/04158bf7ed8935e03612d8e08c09d590 to your computer and use it in GitHub Desktop.
Jenkins
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
function log() { | |
echo "[$(date)]$1" | tee -a /var/log/jenkins_userdata.log | |
} | |
function waitForJenkins() { | |
log "Waiting jenkins to launch on 8080..." | |
while ! nc -z localhost 8080; do | |
sleep 0.1 # wait for 1/10 of the second before check again | |
done | |
log "Jenkins launched" | |
} | |
function waitForPasswordFile() { | |
log "Waiting jenkins to generate password..." | |
while [ ! -f /mnt/jenkins/secrets/initialAdminPassword ]; do | |
sleep 2 # wait for 2 of the second before check again | |
done | |
log "Password created" | |
} | |
# UPDATE PLUGIN LIST | |
curl -L http://updates.jenkins-ci.org/update-center.json | sed '1d;$d' | curl -X POST -H 'Accept: application/json' -d @- http://localhost:8080/updateCenter/byId/default/postBack | |
sleep 10 | |
waitForJenkins | |
# Get Jenkins CLI jar bind-mounted docker volume | |
cp /mnt/jenkins/war/WEB-INF/jenkins-cli.jar . | |
waitForPasswordFile | |
# Get password from bind-mounted docker volume | |
PASS=$(sudo bash -c "cat /mnt/jenkins/secrets/initialAdminPassword") | |
sleep 10 | |
# INSTALL PLUGINS | |
java -jar jenkins-cli.jar -s http://localhost:8080 -auth admin:$PASS install-plugin ${plugins} | |
# RESTART JENKINS TO ACTIVATE PLUGINS | |
java -jar jenkins-cli.jar -s http://localhost:8080 -auth admin:$PASS restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment