Skip to content

Instantly share code, notes, and snippets.

@rfennell
Created January 19, 2018 19:36
Show Gist options
  • Save rfennell/2cc36232158518b3b36866bfd321644d to your computer and use it in GitHub Desktop.
Save rfennell/2cc36232158518b3b36866bfd321644d to your computer and use it in GitHub Desktop.
PowerShell script add a commit to the current repo for use inside a VSTS CI/CD process
(
$file = "readme.md",
$text = "Automated edit",
$wi = "#13 #14"
)
"Set config"
git config --global user.email "[email protected]" # any values will do, if missing commit will fail
git config --global user.name "Build user"
"Select a branch"
git checkout master 2>&1 | write-host # need the stderr redirect as some git command line send none error output here
"Update the local repo"
git pull 2>&1 | write-host
"Status at start"
git status 2>&1 | write-host
"Update the file $file"
Add-Content -Path $file -Value "$text - $(Get-Date)"
"Status prior to stage"
git status 2>&1 | write-host
"Stage the file"
git add $file 2>&1 | write-host
"Status prior to commit"
git status 2>&1 | write-host
"Commit the file"
git commit -m "Automated Repo Update $wi" 2>&1 | write-host
"Status prior to push"
git status 2>&1 | write-host
"Push the change"
git push 2>&1 | write-host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment