Created
July 28, 2025 18:17
-
-
Save Java4all/26ff36e2d5e4e3fffccc6d84fda71017 to your computer and use it in GitHub Desktop.
groovy call
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
| jenkins_create_token() { | |
| local user=$1 pass=$2 name=$3 jurl=$4 | |
| # Get CSRF crumb | |
| local crumb | |
| crumb=$(curl -s -u "$user:$pass" \ | |
| "$jurl/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)") | |
| # Create token | |
| curl -s -u "$user:$pass" \ | |
| -H "$crumb" \ | |
| -X POST \ | |
| "$jurl/user/$(printf %q "$user")/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken" \ | |
| --data-urlencode "newTokenName=$name" | |
| } | |
| # Example usage: | |
| jenkins_create_token "[email protected]" "P@ssw0rd!" "ci-bot" "https://jenkins.example.com" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment