Run a Gitlab Pipeline from previous tag on pipeline failure - gitlab

I have set up a pipeline for my GitLab project. at the end of a successful pipeline, a tag is created. What I would like to add is when a pipeline fails then a pipeline should get triggered using a previous stable tag.
how do I do that? duplicate all the jobs? which runs with a previous tag(stored somewhere) with using only a keyword?
For example
stages-
- deploy
- Tag
job A:
- deploy
job b:
- Tag
Suppose job A fails( job b will not run) then the same pipeline should be created from a tag previously created.

Related

Azure DevOps pipelines - Build triggered multiple times

I am using different YAML files (with different tasks) in different branches.
While triggering it executes multiple times. I don't know what is the reason.
I am using different triggers for different pipelines. eg:
In branch SFCC:
trigger:
- SFCC
In branch SFCC-QA:
trigger:
- SFCC-QA
In branch SFCC-DEV:
trigger:
- SFCC-DEV
When I run the pipeline for SFCC triggered, the same pipeline would start running in another pipeline also with same trigger, because of that app is deploying 2-3 times instead of single time.
Could you please help me with this.
SFCC-QA pipeline:
SFCC pipeline:
You can see in first screenshot(for the date 9th sep and 14th sep), the pipeline is for QA and here pipeline is executing for other branch, which is not mentioned in this particular pipeline. While in the second screenshot pipeline is executing fine for the same date. So you can see 2 times same pipeline is execting on 9th and 14th sep.
Azure build pipeline definition is associated with a repo and YAML file in that repo. The branch is associated at the time only when the pipeline is run. So, it is not something you associate at the time of pipeline definition.
I think in all 3 of your pipelines, the YAML file path is same. You have different trigger (and different other content) in the YAML file in different branches, but your file name/path is same. Hence the same file will trigger the build for each branch where relevant within pipeline.
To get desired results you can use different file name for your YAML file for each pipeline definition. So in SFCC branch have SFCC.yaml and in SFCC-QA branch, have SFCC-QA.yaml.

Gitlab: How to run a deploy job on a tagged version / release?

I have created several releases of my backend service in gitlab. Now I want to be able to pick one of them and run the deployment job in my gitlab pipeline on it. SO that the specific version gets deployed. (I'm creating release notes to each release so I can pick which release should now get deployed.)
This is my deployment job in the gitlab-ci.yml:
So far I have used this job like this: When a feature branch was merged into the master and the stand could be deployed and passed all the tests, then the job was triggered manually in the pipeline overview page. Now that I'm using tags to tag each new master version, I want to be able to deploy a version/release from the tags.
Does anyone have an idea how this could work in principle? It would be best if I had a dropdown menu where I can select one of the releases and then trigger the deployment job for it.
The job needs to not get run in the master pipeline, but in the tags pipeline
only:
refs:
- tags
when: manual
This way I can copy the tag of the version that I want to deploy:
and search for it in the pipelines overview page to then trigger the deploy job manually:

How to not trigger the pipeline after a push inside a pipeline

I am working with files inside a GitLab CI/CD pipeline and push them in the repository at the end of the job.
The problem is that the push itself trigger the run of the pipeline.
I tried to solve this issue by adding the keyword [ci skip] in the commit message.
It is working but still add a pipeline skipped in the history:
Is there another way to skip the pipeline after a push in a pipeline run without seeing this skipped pipeline?
Unfortunately this skipped pipeline can not be hidden, the only solution is to run use workflow only when pipeline is triggered manually or from pipeline, but it will block any commit to create pipeline.
There is an open change for this: gitlab#28369

Using commit triggers to trigger Azure Devops Pipeline in the YAML File

I have a Question about the Pipline trigger in Devops.
My team and I are using Azure Devops to develop a software.
We use a Branch Specific trigger, to start the pipeline only in out Master Branch. The other branches are ignored in the YAML File.
First part of my question is, that we don't know a way how to trigger the Pipeline over a commit message in our Git tool.
For example: "We work in a different branch than the Master branch -->No Pipeline is running. But we want to trigger the pipeline in this Branch for a Specific test just one time. Our way would be to insert a specific command in the commit text to trigger the pipeline."
My second question is, if it's possible to run different stages in different Branches in one YAML file.
Here again an example: " In our different Branch, we just want to run our unit tests every push. In our Master Branch we want to run our unit tests and after that, we want to build our application.
So far, we started the pipeline at every push and build a new image everytime. But we dont want that, because some pushs arent working and we just push it. We want to decide when the pipeline is running and whitch stage is running.
I hope you can understand my problem. For further questions, please comment here.
Thanks
Question 1:
You can consider using tag triggers to do this. Here is an example:
trigger:
branches:
include:
- master
tags:
include:
- test.*
Then the pipeline will be triggered when working on the master branch or the commit tag is test.*.
Question 2:
You can use conditions. Here is an example:
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
Add the condition to your stage, and then the stage will be only triggered by the master branch.
Question 3:
So far, we started the pipeline at every push and build a new image everytime. But we dont want that, because some pushes aren't working and we just push it.
You can skip CI for individual commits.
Just include [skip ci] in the commit message or description of the
HEAD commit and Azure Pipelines will skip running CI.
Update 1:
For Question 1, the test.* means a tag which started with test., such as test.1, test.0.1, and so on. You can change the test.* to anything you want.
As for the question your encountered, you can't create a tag called test.* directly because a tag name cannot contain *.
To avoid confusion, you need to create a tag for the commit to trigger the tag CI, rather than writing it directly in the commit text.
The idea
insert a specific command in the commit text to trigger the pipeline.
I don't think is currently supported and tag trigger is an alternative.
Click this document for detailed information about git tag.
Update 2:
Trigger the stage by master branch or 1620-to-PipelineTrigger branch:
condition: or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.SourceBranch'], 'refs/heads/1620-to-PipelineTrigger'))
You can set only one condition per stage, but you can create more complex conditions using and, or and ().
Click this document to get more detailed information and examples about conditions.

Azure Devops exclude job if branch tag is present

My Azure DevOps pipeline has 3 jobs. One builds the project for production and the other builds it for testing and the last publish artifacts. When I push to release branch, it triggers all of 3 jobs, but they can take 10-15 minutes to finish. What I'm trying to achieve is exclude testing job if a tag is present on the commit or something like that.
Ex. Don't trigger test job if branch tag has "hotfix". Tryed "Run this job with conditions" in job's settings with this value "not(startsWith(variables['Build.SourceBranch'], 'refs/tags/hotfix'))" but if I push something to release with hotfix tag it still runs.
Thanks
We recommend you can use the conditions:
condition: eq(variables['Build.SourceBranch'], 'refs/tags/test')
And this means if you want the test job to run, then you need to push something to release with test tag. We cannot use the value "not(startsWith(variables['Build.SourceBranch'], 'refs/tags/hotfix'))"
On my test, if I push the commit release with hotfix tag, then the test job will be skipped.
Update:
We can use the Custom conditions in Additional options, and set it as :
eq(variables['Build.SourceBranch'], 'refs/tags/test')
More details, you can refer this doc: Expressions

Resources