Branch name variable in TFS YAML pipeline - tfs

I am trying to make a TFS release YAML pipeline which takes resources from specific builds from branches.
For the resources part:
resources:
pipelines:
- pipeline: pipelineA
source: SourceA
project: ProjectA
- pipeline: pipelineB
source: SourceB
project: projectB
This works fine, but it will always release the latest build from pipelineA and pipelineB, regardless which branch it is.
Then I was trying to let it release upon on a specific branch, I tried:
resources:
pipelines:
- pipeline: pipelineA
source: SourceA
project: ProjectA
branch: task/123_task_name
- pipeline: pipelineB
source: SourceB
project: projectB
This works fine as long as there is a build for branch "task/123_task_name".
Now I am trying to let it release upon on the branch I select, I tried:
resources:
pipelines:
- pipeline: pipelineA
source: SourceA
project: ProjectA
branch: $(Build.SourceBranchName) OR $(Build.SourceBranch) OR task/$(Build.SourceBranchName)
- pipeline: pipelineB
source: SourceB
project: projectB
None of them worked, all of them are returning error The pipeline is not valid. Unable to resolve latest version for pipeline pipelineA. This could be due to inaccessible pipeline or no version is available.
What should be the correct format for this branch variable, thanks.

It because you can't put this value in a variable if you're using TFS.
This feature added only to Azure DevOps Services recently:
https://learn.microsoft.com/en-us/azure/devops/release-notes/2022/pipelines/sprint-212-update
resources:
repositories:
- repository: templates
type: git
name: Templates
ref: ${{ variables['Build.SourceBranchName'] }}

Related

Avoid trigger Bitbucket pipeline when the title starts with Draft or WIP

To automate our CI process, I need run the Bitbucket pipelines only when the title not starts with "Draft" or "WIP". Atlassian has only this features https://support.atlassian.com/bitbucket-cloud/docs/use-glob-patterns-on-the-pipelines-yaml-file/.
I tried with the regex ^(?!Draft:|WIP:).+ like this:
pipelines:
pull-requests:
'^(?!Draft:|WIP:).+':
- step:
name: Tests
but the pipeline not start under any circumstances (with or withour Draft:/WIP:). Any suggestions?
Note the PR pattern you define in the pipelines is matched against the source branch, not the PR title. Precisely, I used to feature an empty pipeline for PRs from wip/* branches, e.g.
pipelines:
pull-requests:
wip/*:
- step:
name: Pass
script:
- exit 0
"**":
- step:
name: Tests
# ...
But this workflow requires you to work on wip/* branches and changing their source branch later on. This is somewhat cumbersome and developers just did not opt-in.
This works, though.

Bitbucket pull requests pipeline with specific glob patterns

I am little confused here regarding PR being triggered against main branch?
All branches:
(I know this will trigger pull request from any branch to any branch)
pipelines:
pull-requests:
'**':
Main branch:
(Does this trigger pull request if created from feature/pe-1234 to main?)
pipelines:
pull-requests:
'main':
I want to know what happens if I mention only main. It is not clear in documentation or may be I didn't get it right
The branch name / glob pattern in the pull-request pipeline definition is the source branch that should trigger that pipeline, not the target branch.
E.g. if you were following git-flow instead of github-flow, it would make sense to override the pipeline run by the PR from main to a release/whatever branch so that it simply passes, or does an integration test, but does not perform the usual tests, linting, coverage and whatnot.
pipelines:
pull-requests:
'**': # triggers if no other specific pipeline was triggered
- parallel:
- step: *linting-step
- step: *testing-step
main: # triggers from main to anywhere else
- step:
name: Pass
script:
- exit 0
If following github-flow, you will probably never make a PR from main to anywhere else, so you can safely skip this definition. Only if you wanted PRs from feature/AAA-NNNN branches to trigger a special pipeline besides the testing workflow, you can write an alternate pipeline like
pipelines:
pull-requests:
'**': # triggers if no other specific pipeline was triggered
- parallel:
- step: *linting-step
- step: *testing-step
feature/*: # triggers from feature/* to anywhere else (including to main)
- parallel:
- step: *linting-step
- step: *testing-step
- step: *maybe-hook-issue-tracker-step # ?
so that the simpler default '**' pipeline will not run. But it will run irrespective of the target branch, usually main but not necessarily.

Ignore an approval step for a certain branch CCI 2.0

What I want by default is for my branch to build, then wait for approval to deploy to dev. However, if I push to the dev branch, that should deploy without approval.
I have the following workflow:
workflows:
version: 2
build:
jobs:
- build
- approve-dev:
type: approval
requires:
- build
filters:
branches:
ignore: dev
- deploy-dev:
requires:
- approve-dev
The problem is that when the approve-dev job is skipped, the deploy-dev job loses its requirement, so the only possible step is build.
Is there a way around this?
I have worked out a way to do this, but it's quite verbose, basically you duplicate the workflow at that point, with one copy only for that branch, and one copy which ignores that branch, like so:
workflows:
version: 2
build:
jobs:
- build
- approve-dev:
type: approval
requires:
- build
filters:
branches:
ignore: dev
- deploy-dev:
requires:
- approve-dev
- deploy-dev-auto:
requires:
- build
filters:
branches:
only: dev
Using templates (<<deploy-dev-defaults: &deploy-dev-defaults) to define the tasks means you don't have to rewrite the job, just specify it twice with the two different names.

jenkins multibranch jenkinsfile SVN checkout

I have a Jenkinsfile located in [my svn branch]\build folder, and it checks out code to the slave node and builds.
My multi branch project finds the branch correctly, but it checks out the entire svn branch on the master just to read the jenkinsfile instead of checking out just the jenkinsfile itself of just [my svn branch]\build folder.
This is a major problem because of storage and performance, are there any solutions for that?
In your multibranch pipeline config in 'include' field type: branches/*/build (i assume that you have all svn branches in folder 'branches', and url to your build folder is something like: svn_url/branches/my_new_branch/build)
Then it will scan only build folder in each branch.
Warning - after changing that config property your multibranch pipeline will only diacover 'build', if you want to index other build folders, you can list them in that property, i.e.:
Include: trunk/build, trunk/other_build, branches/*/build, branches/*/other_build
But more clean approach is to get only one build per multibranch pipeline

Travis CI: branch filters in build matrix items

We are wondering whether there is any way to add filters to Travis matrix items. In our particular case, we wish to run certain jobs only on specific branches.
The following example would be an ideal way for configuring this scenario, however it doesn't seem to work:
matrix:
include:
- env: BUILD_TYPE=release
branches:
only:
- master
- env: BUILD_TYPE=ci
branches:
only:
- develop
As a workaround, we can exit from the build script immediately by checking the appropriate env vars (TRAVIS_BRANCH), but it is very far from ideal as launching the slave machine and cloning the repo takes a considerable amount of time.
You can now achieve this with the beta feature Conditional Build Stages
jobs:
include:
- stage: release
if: branch = master
env: BUILD_TYPE=release
- stage: ci
if: branch = develop
env: BUILD_TYPE=ci

Resources