Created
January 10, 2019 15:17
-
-
Save FilBot3/eff47615f5f3111dbc5f5e263d6ae520 to your computer and use it in GitHub Desktop.
Using cURL to authenticate and using Jenkins' Crumb identifier.
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
#!/bin/bash | |
# CloudBees CSRF Explained | |
# => https://support.cloudbees.com/hc/en-us/articles/219257077-CSRF-Protection-Explained | |
# How to install Jenkins Plugins via the API | |
# => https://stackoverflow.com/questions/9765728/how-to-install-plugins-in-jenkins-with-the-help-of-jenkins-remote-access-api | |
# => https://gist.github.com/basmussen/8182784 | |
# Using Jenkins' Crumb | |
# => https://gist.github.com/dasgoll/455522f09cb963872f64e23bb58804b2 | |
# Using a mixture of Shell and Python. | |
#mytoken=$(curl --user 'username:password' -s https://jenkins/crumbIssuer/api/json | python -c 'import sys,json;j=json.load(sys.stdin);print j["crumbRequestField"] + "=" + j["crumb"]') | |
# First get our CSRF Protection Crumb from Jenkins | |
curl --verbose --location --insecure \ | |
--user 'user01':'supersecretpassword' \ | |
--url 'http://localhost:8080/crumbIssuer/api/json' | |
# The Crumb should either be in the format of | |
# --header ".crumb:uniquestringidentifer" | |
# or | |
# --header "Jenkins-Crumb:uniquestringidentifer" | |
# Now we pass Jenkins our Crumb identifier. | |
#curl --verbose --locaiton --insecure \ | |
# --request POST \ | |
# --header "" \ | |
# --user '':'' \ | |
# --url '' | |
# Install specific versions of plugins via the REST API. For some reason, not | |
# Groovy, which is super annoying because everything else is in Groovy. | |
# => https://gist.github.com/basmussen/8182784 | |
curl --verbose --location --insecure \ | |
--request POST \ | |
--data '<jenkins><install plugin="[email protected]" /></jenkins>' \ | |
--user 'user01':'mysupersecretpassword' \ | |
--header '.crumb:uniqueidentifier' \ | |
--header 'Content-Type: text/xml' \ | |
--url 'http://localhost:8080/pluginManager/installNecessaryPlugins' | |
# => https://gist.github.com/basmussen/8182784#gistcomment-2734311 | |
# Supposedly you don't need to do this anymore? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment