Azure / Azure/pipelines

Predefined `Build.SourceBranch` variable not working

Open
#38 2 comments 1 reaction 0 assignees View on GitHub
bug idle P1
Dominant language
TypeScript
Stars
85
Forks
99
PR merge metrics
No merged PRs in 30d

Description

Hi,

We're trying to migrate from `pr` triggers in the `azure-pipeline.yml` to a GitHub Action trigger, using the following action:
```
...
azure_pipeline:
needs: [previous_action]
runs-on: ubuntu-latest
steps:
- name: Azure Pipelines Action
uses: Azure/pipelines@v1
with:
azure-devops-project-url: https://dev.azure.com/organization/project
azure-pipeline-name: cogz-ci
azure-devops-token: ${{ secrets.AZURE_DEVOPS_TOKEN }}
```
The trigger works great, but some of the build information is missing.

For example, our build name in the `azure-pipeline.yml` file is defined as follows:
`name: cogz-ci-$(branchName)-$(Date:yyyyMMdd)$(Rev:.rr)`
`branchName` is defined in a global template as:
```
${{ if startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}:
branchName: $[ replace(replace(replace(variables['system.pullRequest.sourceBranch'], 'refs/heads/', ''), '\', '-'), '/', '-') ]
${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/') }}:
branchName: $[ replace(replace(replace(variables['build.sourceBranch'], 'refs/heads/', ''), '\', '-'), '/', '-') ]
```

When running with the azure pipelines PR trigger, we get:
![image](https://user-images.githubusercontent.com/4647811/121728901-dc616e80-cabb-11eb-8533-42d14ac0ae6a.png)

But when running with the GitHub Action trigger, we get:
![image](https://user-images.githubusercontent.com/4647811/121728968-ed11e480-cabb-11eb-99ff-83e03b90e91f.png)
(the build also fails because we're using `branchName` in a lot of places)

Are we missing something? Should this be passed as a variable when using the GitHub Action trigger?

Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.