Azure DevOps resources repo: self - azure

Can someone please explain or provide documentation for
resources:
- repo: self
in the azure-pipelines.yml files? I cannot find any documentation for it.
Here's the official Azure docs:
https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema

"self" means "the repository that the YAML file is in".

Daniel Mann answered this question. It turns out, I did not need the repo: self part. This part is what I actually put in my YAML azure-pipelines.yml file and it is working for us. Thanks again!
trigger:
branches:
include:
- master
- features/*
- bugs/*
paths:
exclude:
- README.md
jobs:
- template: path/to/backendRepo/azure-pipelines.yml
parameters:
componentName: BackEndStuff
- template: path/to/frontendRepo/azure-pipelines.yml
parameters:
componentName: FrontEndStuff

https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#access-to-github-repositories
I was wondering the same, and managed to find this, that actually documents what the earlier answers describe

Related

How to prevent build for new branch creation in azure devops yaml

In Azure DevOps, created pipeline using Yaml file and mentioned "develop" under Triggers section. It is triggering for new commits in develop branch but also triggering for new branch creation based on "develop" branch which is not happening when I create a static pipeline. How can I prevent build for new branch. Any help here?
I think you should use the include / exclude filters like below :
# this is being defined in app-ci pipeline
resources:
pipelines:
- pipeline: securitylib
source: security-lib-ci
trigger:
branches:
include:
- releases/*
exclude:
- releases/old*
Just check this page and you should find your answer : https://learn.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers?view=azure-devops
Regards
Could you try this ?
trigger:
batch: true
branches:
include:
- develop

Azure pipeline - trigger on feature branch

My azure-pipeline.yml is defined like this:
trigger:
branches:
include:
- master
- develop
steps:
-task1
-task2
-task3
On each push to develop branch the pipeline is triggered - as expected.
I want to trigger the same pipeline on the feature branch.
I created the new branch from develop branch. The name is featureBranch.
I edited azure-pipeline.yml to look like this:
trigger:
branches:
include:
- master
- develop
- featureBranch
steps:
-task1
-task2
-task3
When I push the code to featureBranch the pipeline will not trigger. I have tried also this but without success:
trigger:
branches:
include:
- '*'
A common error scenario is that there are UI Settings which override your YAML-Settings. You can check that in ADO-UI under Pipelines -> the "three dots" -> Triggers.
Also try to include filepaths to further test your scenario:
> trigger:
> paths:
> include: *
Agree with vollmer.io. You could edit this yaml pipeline and check its Triggers settings.
If there are UI trigger settings which override your yaml trigger settings.
In addition, if you want to trigger this pipeline when there are pushes to all branches, the following syntax should work.
trigger:
branches:
include:
- /*
See: CI triggers for more details.

How to refer variable name in .common tag in gitlab cicd

I have a gitlab yaml file. I have variables part and .common tag part in it as below:
variables:
name: app
env: prod
.common:
tags:
- &env_tag prod
My question is can we pass the env variable to .common tag part. While trying to refer the variable name, it was failing
I have tried as below:
.common:
tags:
- &env_tag $env
Unfortunately this is not possible right now as gitlab does not support variable expansion in tags.
There are currently multiple open issues regarding this feature:
https://gitlab.com/gitlab-org/gitlab/-/issues/35742
https://gitlab.com/gitlab-org/gitlab-foss/-/issues/24207

Azure Pipelines "Require Template" check not working

I am trying to get the "Require template" check working on a protected resource (Agent Pool, Service Connection, etc) in my Azure Pipelines.
I've got a shared template setup in a common repository (named "goldenimage-azure-pipelines-templates") that is defined as follows:
# /templates/pipelines/master.yml
parameters:
- name: templates
type: object
default: []
stages:
- ${{ each template in parameters.templates }}:
- ${{ each pair in template }}:
${{ if eq(pair.key, 'template') }}:
${{ template }}
Then I have a set of shared templates in the same repository that are referenced by the consuming azure-pipelines.yml file.
# /templates/stages/main.yml
stages:
- stage: mainBuild
jobs:
- template: /templates/jobs/set-version.yml
- template: /templates/jobs/build-image.yml
- template: /templates/jobs/cleanup-build.yml
- template: /templates/jobs/test-image.yml
- template: /templates/jobs/cleanup-test.yml
- template: /templates/jobs/update-configmap.yml
- template: /templates/jobs/destroy-template.yml
- template: /templates/jobs/cleanup.yml
Now, in my consuming repository, I have the azure-pipelines.yml file defined as follows:
# azure-pipelines.yml
name: $(GitVersion.NuGetVersionV2).$(Build.BuildId)
trigger:
branches:
include:
- master
paths:
exclude:
- 'README.md'
resources:
repositories:
- repository: templates
type: git
name: goldenimage-azure-pipelines-templates
ref: feature/WI443-baseTest
variables:
- template: /templates/vars/main.yml#templates
- template: /azure-pipelines/vars.yml
extends:
template: templates/pipelines/master.yml#templates
parameters:
templates:
- template: /templates/stages/main.yml
And then in my protected resource (Agent Pool or Service Connection), I've defined the check as follows:
But whenever the build runs, it ALWAYS reports that it has failed this check.
I've tried changing the syntax for the Ref to several different options such as:
feature/WI443-baseTest
refs/heads/feature/WI443-baseTest
refs/tags/extend (made this tag just for this test)
I've also tried adding and removing the leading slash on the path to the template, and well as adding #templates on the end of it.
In addition, I have added and removed the template on both the Service Connection, and the Agent pool (in case it would work with one, but not the other).
No matter what I do, it reports that the run is not extending the template. However, I can see in the pipeline the jobs from the template, so it's obviously pulling it.
What am I doing wrong?
No matter what I do, it reports that the run is not extending the
template. However, I can see in the pipeline the jobs from the
template, so it's obviously pulling it.
The direct cause of the issue is that your pipeline doesn't pass the Require Template check. I think the jobs are canceled because of that.
I found it could work well if all my resources were in branch whose format was feature. and same issue occurred if I used a branch like feature/xxx. So I think the second format branch is not supported well in Require Template check .
Check the pic above, according to my tests the check works well for DevBranch, but not Feature/Test. I suggest you can post a feature request here to report this issue. Thanks for your help to make our product better :)
resources:
repositories:
- repository: templates
type: git
name: goldenimage-azure-pipelines-templates
ref: feature/WI443-baseTest
the ref in the pipeline should add the ref/tags/* or at your case ref/heads/feature/WI443-baseTest
in the security approval is the same too, you may refer this article for more information here

Can GitLab pages be used for review apps on a mkdocs project?

This answer by #joki to a previous question suggests that it is possible to deploy each active branch in a GitLab repo to a dynamic environment, by giving browsable artifacts a public URL.
Trying this out with a mkdocs material project, I've found two issues.
Firstly, if the GitLab repo is within a group or a subgroup the URLs in the .gitlab-ci.yml file needs to be something more like this:
environment:
name: review/$CI_COMMIT_REF_NAME
url: "$CI_PAGES_URL/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
auto_stop_in: 1 week
variables:
PUBLIC_URL: "$CI_PAGES_URL/-/jobs/$CI_JOB_ID/artifacts/public/"
Secondly, relative links within the site don't work well, leading to a lot of 404 errors, and the loss of things like style files. Possibly the URLs above are not right, or maybe the site_url in mkdocs.yml needs changing to something like:
site_url: !!python/object/apply:os.getenv ["CI_ENVIRONMENT_URL"]
however, neither of these quite worked for me.
A minimal MR with a very small deployment and review app can be found here.
Does anyone have a working recipe for mkdocs review apps?
You can see the URL you need in the »Browse« button of the build step in your pipeline.
Does this work?
develop:
artifacts:
paths:
- public
environment:
name: Develop
url: "https://$CI_PROJECT_NAMESPACE.gitlab.io/-/snim2-test-subgroup/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
script: |
# whatever
stage: deploy
variables:
PUBLIC_URL: "/-/snim2-test-subgroup/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public"
You'll also need your change to mkdocs.yml to actually use the PUBLIC_URL, and make sure it's used everywhere that absolute internal links are generated:
site_url: !!python/object/apply:os.getenv ["PUBLIC_URL"]
use_directory_urls: false
…

Resources