Reputation: 11
I'm new to azure pipelines. I have build job with azure pipeline and source code are in same branch dev and running fine but is it possible to have azure pipeline and source code in separate branches?
If so, kindly help me on this
Additionally how can i achieve branch parameterized job in azure pipelines?
Upvotes: 1
Views: 336
Reputation: 1
What are you trying to do? In your YAML file you can specify branches for scheduled tasks and triggers. For schedules:
schedules:
- cron: "*/5 * * * *"
displayName: 25th 5:30 AM (IST) Every Month
branches:
include:
- master
- another-branch-here
For triggers:
trigger:
- master
To my understanding, it will always run on the same branch of your repo (matching if your repo is Azure, not sure about the others), but you can update the YAML to get around that.
Upvotes: 0
Reputation: 40603
No, this is not necessary. When you define a pipeline for already existing file you can select a branch:
You can even put a pipeline definition in a different repo and benefit from multiple repo pipeline to achieve this goal.
If you want to parameterized pipeline you should take a look at templates:
# File: templates/npm-with-params.yml
parameters:
- name: name # defaults for any parameters that aren't specified
default: ''
- name: vmImage
default: ''
jobs:
- job: ${{ parameters.name }}
pool:
vmImage: ${{ parameters.vmImage }}
steps:
- script: npm install
- script: npm test
And then you can use it in this way:
# File: azure-pipelines.yml
jobs:
- template: templates/npm-with-params.yml # Template reference
parameters:
name: Linux
vmImage: 'ubuntu-16.04'
- template: templates/npm-with-params.yml # Template reference
parameters:
name: macOS
vmImage: 'macOS-10.14'
- template: templates/npm-with-params.yml # Template reference
parameters:
name: Windows
vmImage: 'vs2017-win2016'
You can also use template froma different repo. Assuming you have common.yml template in Contoso/BuildTemplates repo:
# Repo: Contoso/LinuxProduct
# File: azure-pipelines.yml
resources:
repositories:
- repository: templates
type: github
name: Contoso/BuildTemplates
jobs:
- template: common.yml@templates # Template reference
EDIT:
And in terms of this question:
Additionally how can i achieve branch parameterized job in azure pipelines?
This is possible but not using built-in feature for getting repositories. What you need is use for instance powershell task and this command:
GIT clone -b <branch> https://<PAT>@dev.azure.com/Organization/My%20Project/_git/MyRepo
Please also put in your YAML also checkout: none
as we don't want to get source code by standard pipeline task.
In above command you must put PAT token. More about this you will find here
Upvotes: 1
Reputation: 11
Thank you quick reply on this Checkout code from different repo worked fine But regarding the parameterizing the branch name I used the following but didn't work
Example
- name: branch
displayName: Branch Name
type: string
default: dev
values:
- dev
- test
resources:
repositories:
- repository: project
type: git
name: project
ref: ${{ parameters.branch }}
Upvotes: 0