Created
May 16, 2022 08:32
-
-
Save birolemekli/b9f17abd73a56422bd13e45ae65ce923 to your computer and use it in GitHub Desktop.
How to trigger Jenkins Job with Bash Script
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_URL="http://jenkins" | |
JENKINS_USER="username" | |
JENKINS_TOKEN="username_generate_token" | |
JOB_NAME="job/birolTestJob" | |
JENKINS_AUTH="$JENKINS_USER:$JENKINS_TOKEN" | |
CRUMB=$(curl --user "$JENKINS_AUTH" "$JENKINS"'/crumbIsuser/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') | |
RESPONSE_ERROR=$(echo "$CRUMB" | grep "<html>" || true ) | |
if [ -n "$RESPONSE_ERROR" ] | |
then | |
echo "CRUMB ERROR" | |
exit 1 | |
else | |
curl --user "$JENKINS_AUTH" -H "$CRUMB" -X POST "$JENKINS/$JOB/"buildWithParameters? -F variable1="variable1" -F variable2="variable2" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment