Skip to content

Instantly share code, notes, and snippets.

@CosetteN
Last active February 1, 2017 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CosetteN/984235e953ceea02058d45957a614331 to your computer and use it in GitHub Desktop.
Save CosetteN/984235e953ceea02058d45957a614331 to your computer and use it in GitHub Desktop.
Expect script for Jenkins to determine if current git branch is desired branch. Using "git branch" & matching the current branch with the * worked in terminal but not when started by Jenkins. Script returns only the current branch name, w/out the asterisk, allowing pattern match to work as expected.
# Your script here that logs into your git repo
expect "$"
# Echo current git branch without the dreaded *.
send "git rev-parse --abbrev-ref HEAD\r"
expect {
default {
#If current branch isn't what you want to test on, error out to ensure Jenkins recognizes problem.
puts "Site is not on desired branch. Force error."
error
}
"$branch" {
#If siteis pointed at desired branch, perform git pull and exit.
puts "On correct branch, perform git pull."
send "git pull\r"
expect "$"
}
}
#Your script to exit out of terminal here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment