Skip to content

Instantly share code, notes, and snippets.

@birolemekli
Created May 16, 2022 08:32
Show Gist options
  • Save birolemekli/b9f17abd73a56422bd13e45ae65ce923 to your computer and use it in GitHub Desktop.
Save birolemekli/b9f17abd73a56422bd13e45ae65ce923 to your computer and use it in GitHub Desktop.
How to trigger Jenkins Job with Bash Script
#!/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