0

Im trying to execute some git commands on the Release configuration of Team Services.

I followed this guide to allow git on my Repo. By now i can only execute this commands on the Build configuration, so i create a command line task and execute a git command there, and it works normally.

But in my Release definition, i would like to make a ´git branch´ after change the enviroment. when i try to execute a git command on my command line task e get this message: fatal: Not a git repository (or any of the parent directories): .git this because the Release tries to execute the command problably on my drop folder.

How can i execute a git command on my repo on aRelease task.

6
  • Hi, could you provide an example of what do you want to do with git on the Release step? Commented Jun 26, 2017 at 13:45
  • I have a ´test/production´ enviroment on my release config. test is triggered when a build is succeed. For production enviroment we need to approve manually. If test is ok, we approve to production deploy. In this step of production deploy i would like to make a git tag on a speciefic branch. Commented Jun 26, 2017 at 14:01
  • I think you would need not only do git branch but also git clone or git pull beforehand. So that you get a repo first - and then create a branch on it. Otherwise, git can't operate on the remote repo without having it fetched in the first place. Commented Jun 26, 2017 at 14:09
  • Make sense. By the way, i have no much experience with CD enviroments. Is it usual (good practice) to make git operations on the Release configuriation? The example that i post on OP works but just on the build configuration. Commented Jun 26, 2017 at 14:11
  • I think there is nothing wrong about it as long as you can see this step on your CD flow map so that it is not gets obfuscated. For example, often auto-merging techniques are used when a commit passes tests and deployment to staging. Which are in fact git operations. Commented Jun 26, 2017 at 14:15

1 Answer 1

1

As you realized, it’s caused the artifacts you copied to $(build.artifactstagingdirectory) just part of files (such as **\bin\$(BuildConfiguration)\**) not the whole source code in build definition. So there has no such a .git folder in drop folder (build artifacts).

If you need to check git repo information in release, you should specify the contents of copy files task as ** in build. Then you can use git commands in release.

enter image description here

To run git commands on release, you should change the current path firstly. It is because current working directory for release like C:\_work\r1\a, but your git root path like C:\_work\r1\a\buildName\drop. So you’d better use powershell task to run git commands. Settings for PowerShell task:

Type: Inline Script Inline Script:

cd buildName cd drop git branch -a 

Note: Since there has no local branches for source code, you should use git branch -a to find all the branches in source code and current HEAD.

Sign up to request clarification or add additional context in comments.

6 Comments

I got it to work on the aspect that now i can see my .git folder on the release drop artifact. But now im getting this error when i try to push my new branch, fatal: could not read Username for 'https://myteamservice.visualstudio.com': Invalid argument. I followed this guide ( visualstudio.com/en-us/docs/build/scripts/git-commands ) to give permissions but this guide seems to be just for de build configuration and not for the release configuration.
It doesn't need permission since the artifacts were download locally. You can use the powershell task to execute git commands which I added details in my answer.
im running the git commands on the arctifact drop folder already, and it executes the git commands ok, the problem is when i try to push to remote.
It's caused by the HEAD is not point to any branches, you can create a branch (git checkout -b temp), and then push to remote (git push origin temp or git push origin master).
i can do all read operations, create branch and etc. but the error occours when i try to push my changes to the origin. ´fatal: could not read Username for 'myteamservice.visualstudio.com': Invalid argumen´
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.