0

I am working on an Azure pipeline for a dotnet core project that runs on Windows Self hosted agent. I want my pipeline to use Git commands to check out the release branch and merge the develop branch into it. Next steps will be to build the release branch and deploy to intranet servers

I don’t know Git wording very good, I was using TFS for years. I use the commands below and got the logs here:

- task: CmdLine@2
  displayName: Checkout Release branch
  inputs:
    script: |
      @echo off
      git checkout release
      git pull develop
      git status

From the logs, I understand:

  • It downloads the content of the develop branch because it is the default branch in GitHub, I’d rather want the release branch but I believe Azure is like that
  • I manage to switch to release but I have these errors that I don’t understand: ##[error]Previous HEAD position was bc94bd2 Update Staging Build Pipeline.yml ##[error]Switched to branch 'release'
  • I understood that pull can be used with local or remote branch so I use it to fetch and merge the develop branch to the release branch but I get: [error]fatal: 'develop' does not appear to be a git repository
  • Do I have to specify credentials on every calls to git?
  • On the last step, it fetches again the code from the develop branch and I understand why

If you could help me improve my script, that would be great, Many thanks.

4
  • Can I ask for some clarification as to what you are trying to do? - Is there a specific reason you are not using a repo resource and the dedicated checkout step? If you dont know what this is, thats ok, we can go over that. - Is your repo that you are checking out the same as the one where the pipeline yaml is? - Is your repo in Azure DevOps repos or somewhere else? - I think you are trying to checkout a branch (called release) from a repo. Is this correct? Commented Jul 27, 2020 at 10:42
  • Thank you for asking. I am reproducing how the team currently work with TeamCity not knowing much about old one or new one, so I can get confused. The process is: developers commit to develop branch, a pipeline triggers on commits, build the develop branch, creates an artifact that gets deployed to DEV server. Commented Jul 28, 2020 at 8:38
  • When the scrum master is pleased with DEV, he triggers manually the merge from develop to release branch when complete, it triggers a pipeline to build the release branch and create an artifact that gets deployed STAGING server. Commented Jul 28, 2020 at 8:38
  • I’m not sure about “repo resource” and “checkout step”, the repo is GitHub, we would like to build this and later slowly move projects to DevOps repos. Yes, I stored my yaml files in the same repo I am building. I have a folder for source files and a folder for pipelines and one sub folder for each pipeline. Yes, I am trying to check out the release branch to next merge the develop branch into it. Commented Jul 28, 2020 at 8:38

1 Answer 1

1

You can use git merge commands to merge branches. To merge develop branch into release branch you can use git merge origin/develop. Check the document for more information. See below example:

steps:
- checkout: self
  persistCredentials: true
- task: cmdLine@2
  inputs:
    script: |
      @echo off
      git checkout release
      git merge origin/develop
      git status 

However, it is not recommended to deploy release branch in above way. You can change the default branch of your azure pipeline to release branch and enabled the Continuous Integration trigger for release branch.

So that you can create a pull request to merge develop into release from the github UI or by using commands. After develop is merged into release, the azure pipeline will be automatically triggered to deploy from release branch. Note: the azure pipeline yaml file must exist in release branch too. See below steps:

1, To change azure pipeline branch from develop to release:

On your azure devops pipeline Edit page, Click the 3dots and click Triggers

enter image description here

Go to YAML tab--> Get Sources-->Click the 3dots to change the default branch.

enter image description here

2, Set CI trigger for release branch

In the azure pipeline yaml file, set the trigger to include release branch(You can also set PR trigger):

(Actually you do not need to follow above steps to change the default branch. You just need to include the azure pipeline yaml file in release branch and set the CI trigger to include release branch as below)

 trigger:
   branches:
     include:
     - release
     exclude:
     - develop #if you want disable CI trigger for develop branch

By adding the CI trigger to include the release branch in the azure pipeline yaml file. Azure pipeline will automatically be triggered on release branch when merging from develop into release branch.

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

8 Comments

Thank you for all this. I changed my default branch to release but when I start the pipeline, it shows a UI where I can’t run unless I provide a commit, I don’t know why. When default is develop, it doesn’t require commit
Sorry i can not reproduce this scenario. In my pipeline the commit is optional. You can try refresh the page, or recreate a new pipeline and choose using existing azure pipeline YAML file and select release as default branch.
Meanwhile I've set back default to develop and updated the script to git checkout release and git merge origin/develop Log shows: Your branch is up to date with 'remotes/origin/release'. Two errors: Previous HEAD position was 0a85d4c UpdatePipeline.yml and Switched to branch 'release', Merge made by the 'recursive' strategy. Your branch is ahead of 'remotes/origin/release' by 190 commits. (use "git push" to publish your local commits) Log shows nothing to commit, working tree clean but I still need to use git push I guess.
Concerning PR, I understand the recommend approach would be that when scrum master is happy with develop branch, he goes to GitHub to request a PR from develop to release or is there a way for him to request the PR from Azure DevOps? Thanks a lot!
The error showed the develop branch is merged to release branch which is downloaded by the pipeline on the agent machine. You donot have to push back to your github repo.Unless you want the release branch on github is synced with the merged release on your agent machine.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.