Last active
February 1, 2017 23:52
-
-
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.
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
# 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