Azure pipeline use star in trigger paths include - azure

I want to create a pipeline trigger in azure devops that triggers only on changes in folder named src/Subscription.*
My Folder structure:
src
Subscription.Data
Subscriptin.Api
Subscription.Shared
How my pipeline looks
trigger:
branches:
include:
- development
- master
- release
paths:
include:
- src/Subscription.**/*
How can i change the include to trigger on file changes in all the folders ?

How can i change the include to trigger on file changes in all the folders ?
Until September 8, 2021, this is still a known request on our main product forum:
Support wildcards (*) in Trigger > Path Filters
Now, it is possible now as it is written here, but the function needs to be improved:
Wild cards can be used when specifying inclusion and exclusion branches for CI or PR triggers in a pipeline YAML file. However, they cannot be used when specifying path filters. For instance, you cannot include all paths that match src/app//myapp*. This has been pointed out as an inconvenience by several customers. This update fills this gap. Now, you can use wild card characters (, *, or ?) when specifying path filters.
Now, we could use * but not ** & *.
As workaround for this issue:
trigger:
branches:
include:
- development
- master
- release
paths:
include:
- src/Subscriptin.Api/*
- src/Subscription.Data/*
- src/Subscription.Shared/*

Related

How to exclude everything that is not in the include - Azure DevOps YAML Pipeline

If I have a trigger that looks like this:
trigger:
branches:
include:
- main
paths:
include:
- abc/def/*
Is everything that is NOT in that path automatically excluded? If not, how can I exclude everything that is not in that path abc/def/*?
According to your YAML trigger file, it should be excluded everything that is not in the include path. It is equivalent to exclude *.
You can specify file paths to include or exclude in the YAML file.
When you specify paths, you must explicitly specify branches to trigger on. You can't trigger a pipeline with only a path filter; you must also have a branch filter, and the changed files that match the path filter must be from a branch that matches the branch filter.
For more information, you could refer to Paths in YAML Trigger.

Run different Gitlab pipeline jobs depending on the tag

I would like to achieve this Gitlab CI/CD behaviour:
Two jobs defined in the pipeline:
job_beta triggered when a tag is created with a semver number containing a "-rc*" suffix. For example: v1.0.0-rc1.
job_production triggered when a tag is created with a semver number, without any suffix. For example: v1.0.0.
Is there a way to parse the $CI_COMMIT_TAG variable in the .gitlab-ci.yml file of the project? Or any other ideas about how to achieve this?
To achieve this kind of behaviour, you can rely on the only keyword to control which job will be created. Simply specify a regular expression that will either match a semver with the rc suffix or one without any suffix.
You could do it the following way if your semantic versions are prefixed with v:
build-beta:
image: your-build-image:latest
stage: build
only:
- /^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$/
script:
- ./build-beta.sh # Do something...
build-prod:
image: your-build-image:latest
stage: build
only:
- /^v[0-9]+\.[0-9]+\.[0-9]+$/
script:
- ./build-prod.sh # Do something...
You can also achieve something similar with the rules keyword by matching $CI_COMMIT_REF_NAME with the appropriate regex in an if condition.

How to send different strings to different hosts depending on the file that was commited. (gitlab ci/cd)

I'm absolutely new to all this ci/cd thing and its documentation is too extensive. So i'd like to apologize in advance if there is too easy question.
I have gitlab repo with many configs for different services i.e:
project_folder
--global_conf.json
--service1
----config_folder
------....
--service2
----config_folder
------....
--service3
----config_folder
------....
I'd like to know what should I do (just general plan and some key words to search documentation more precisely already would be fine) to send to hosts [host1:port, host2:port, host3:port] different strings with commands "check {service_name} for changes" or "check {global_config} for changes" e.t.c, depending on the file that was committed.
I already have my service on each host that could perform different operations for different task's strings, so I need just send them that task.
You'll propably end up using "only: changes" as explained here.
Something like this should fit:
stages:
- trigger
service1:
stage: trigger
script:
- curl http://host1:port1
only:
changes:
- service1/*
service2:
stage: trigger
script:
- curl http://host2:port2
only:
changes:
- service2/*

Gitlab only running tests based on changed modules?

Lets say I have a test block for all my microservices (15-20+). Tests take a long time since there are so many disparate modules in this monorepo.
Lets say I only want to run 1 or maybe 2 at a time if and only if specific code changes have been made underneath a path. How can I best do this? For assembling I do something like this (not sure if this is terrible or not)
Ultimately, I'm trying to only build and test relevant things if they're relevant (based on if they or a related module I can define change)
Module-specific assembles
x:
stage: build
image: gradle:6.0-jdk11
script:
- gradle :x:assemble
artifacts:
paths:
- x/build/libs
only:
changes:
- x
- x/*
- x/*/**
y_build:
stage: build
image: gradle:6.0-jdk11
script:
- gradle :y:assemble
artifacts:
paths:
- y/build/libs
only:
changes:
- y
- y/*
- y/*/**
Current block for testing
test:
stage: test
image: gradle:6.0-jdk11
services:
- name: gitlab-registry.company.com/nap/dynamodb-local:1252954
command: [ "-inMemory", "-sharedDb" ]
alias: dynamodb
script: gradle check
There are many ways that a Gitlab CI Pipeline can be triggered, but the basic way is when a commit is pushed, no matter what the change is. Currently, there isn't a way to inspect which parts of the code are changed, and only run some steps or others based on the result, but you can control which steps run based on the branch or tag name.
So for example, you could have steps that only run when the branch name starts with something like "microservice_3_", and then make sure that when editing Microservice 3, you always start the branch name with "microserver_3_", though this could get complicated the more microservices you have to support.
The easier option (in terms of the pipeline definition) is to maintain the microservices in separate repositories, each with their own pipelines and tests. This way each individual pipeline only runs against a specific component and doesn't care about changes to the others. Then if you need to, you can combine the microservices in another repository (included as git submodules) and have a pipeline that only cares about the services as a whole.
This would add extra overhead while developing the project(s), but it makes the pipelines easier to manage.

GitlabCI run pipeline on specific branch using wild card

I want to trigger a pipeline everytime the current milestone branch changes it works fine with hardcoded milistone number
the problem is that we increase the milestone number, every 2 weeks
and gitlab runner doesn't parse .gitlab-ci.yml wildcards
so things like that not working
job:
only:
- milestone-*
i also tried regex as suggested BY Makoto Emura here at the comments
java:
only:
- /^mileston-.*$/
for now i use it this way and update my .gitlab-ci.yml after creating a new milestone
job:
only:
- milestone-10
I try to look for an environment variable for target branch but didn't find any
Does anyone know a solution?
I tested with this regex and it works :
only:
- /^milestone-.*$/
In your comment, you wrote /^mileston-.*$/ instead of /^milestone-.*$/ (the e is missing at the end of milestone)

Resources