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

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

Related

Azure Devops pipeline triggering twice with Build Validation

I have created a pipeline in my repository which is used to validate code by executing unit tests for code that is being pushed to features/* branches. The same pipeline is used as Build validation pipeline set as Branch Policy on the develop branch to validate incoming PRs. This is the trigger of the pipeline.
# pipeline.yml
trigger:
batch: false
branches:
include:
- features/*
However we have come across the following condition: Given an open PR from refs/heads/features/azure-pipelines -> refs/heads/develop we push a commit on the features/azure-pipelines branch.
This causes the pipeline to trigger twice. To my understanding one of the runs is due to the trigger of the pipeline (The one marked as Individual CI on the screenshot) and the second run is due to branch policy trying to validate code being pushed onto the open PR to develop. (The PR Automated)
Is there any way to disable one of the executions since it's essentially a duplicate? I was maybe looking for a way to retrieve open PRs and abort execution of a pipeline for Individual CI if there is an open PR for a branch but I am not sure that's the best way around that and I am looking for options.
You can set
trigger: none
This way only the branch policy will trigger the pipeline.
Is there any way to disable one of the executions since it's essentially a duplicate?
As we know, we could not disable the Build validation pipeline set as Branch Policy on the develop branch to validate incoming PRs unless we cancel the Build validation.
For your situation, you could try to include [skip ci] in the commit message or description of the HEAD commit to make the Azure Pipelines skip running CI when you plan to merge the features branch to the develop branch.
You could check the document Skipping CI for individual commits for some more details.
Here it depends if they does the same. You can have conditional checks in the pipeline which does a different things for PR and CI runs. However, I'm pretty sure that this is not possible, because one is defined on the YAML and the second on the Azure DevOps portal. So even if you disnle PR trigger here in YAML, a branch policy still runs a PR. And you can specify antyhing in YAML to block branch policy.

How to Trigger a pull request using script or pipeline once build is successful from azure devops

I have a requirement. Whether it is possible or not I don't know
Requirement: I have three branches 1. Master, 2. Dev, 3. Test.
Here every time new code is committed to dev or test and we create a build to execute the code. Now the requirement is I don't want to merge the code to Master branches unless build is success for master. When build is successful then only PR will be triggered and code will be merged to Master Branch.
Master build ---> Success ----> Then merge code with Master Branch.
Is this possible, without merging the new code into main branch, how can we test the new code from master branch in the build. And if that build is success then only PR has to take place and merge the code in master branch.
My requirement is Once the normal build is success then only PR has to be triggered and merge the code with master branch. Can this be achievable with powershell/bash script that can trigger a PR from pipeline (Build)
I'm pretty sure what you are looking for is branch polices Build validation instead of trigger a PR from pipeline.
You may not fully understand the logic of Build validation and PR.
What you want to achieve is to protect the master and not merge the PR on the branch to the master until the build verification success.
So, the key point is to verify the code after the PR merge, instead of triggering the PR after the build is completed. Otherwise, your build will always be the code on the master before the merge, and this verification will be meaningless.
Adding the Build validation on the master branch, which will trigger the build pipeline when we create a pull request. When we create a PR, it will create a temp commit to save the merged code and build pipeline will checkout this new temp commit to build. If build successful, then we could complete the PR, otherwise, we could not complete the PR, the master code would not be updated.
That should be what you want.
Azure DevOps uses branch polices to achieve this which you can read about Here

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.

GitLab Checking pipeline status - running forever

I've enabled the option - Settings/General/Merge Requests/Merge Checks - Pipelines must succeed.
Since then every merge requests automatically starts execution of the pipeline which is actually what i want. The problem is that this is running forever , i'm receiving message : Checking pipeline status
If i run the pipeline manually from CI/CD Pipelines - Run pipeline finish immediately. I don't understand what is wrong and why it stuck , can i check logs somewhere or something ?
For testing , the pipeline is really simple , just exit 1 .. but still not working ..
At this stage , "running pipeline" is not listed in pipeline list even if the status in merge request is
Checking pipeline status
We ran into a case where a merge request does not contain the .gitlab-ci.yml file. The fix is simply to do a rebase
For troubleshooting purposes, pipelines can be run manually on particular branches at CI/CD -> Pipelines -> Run Pipeline
For me what happened that .gitlab-ci.yml file was having issue as I have mentioned "master" as value for "only" label .. , then everything worked after updating it with my correct branch name which IMO should be "main"
Encountered this myself just now, using Gitlab shared runners. Tried re-running one individual job from the pipeline in the hope that it would resolve the issue. It did not. The best way is to change the commit id of the latest change in the MR.
You can either create an empty commit as suggested by #Bhargav11 or, to keep a cleaner commit history, do
$ git commit --amend --no-edit
$ git push --force
on your branch.
check if current branch you are checking the pipeline status and branch specified in "only: field" are same
only:
- master
This happens to me with pipelines that has no job that triggers on merge-requests.
If I have no tests or anything I wish to run during a merge requests I create a "dummy" job that doesn't do anything.
Rule to trigger on merge requests:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
Then add a simple echo in the script section:
script: echo "Dummy job for merge-request"
Just add an empty commit to trigger it again.
git commit -n -m "commit comment"
From GitLab documentation:
"Checking pipeline status" message
This message is shown when the merge request has no pipeline
associated with the latest commit yet. This might be because:
GitLab hasn't finished creating the pipeline yet
You are using an external CI service and GitLab hasn't heard back from the service yet.
You are not using CI/CD pipelines in your project.
You are using CI/CD pipelines in your project, but your configuration prevented a pipeline from running on the source branch for your merge request.
The latest pipeline was deleted (this is a known issue).
I found what was wrong in my case. The problem was with the runners. There was "Shared runners" enabled by default which caused the confusion. I've just disabled them and enable my own runner and everything started to work as expected. You can check this in CI / CD Settings, I think they are enabled by default. Basically , pipelines are nothing more than a trigger for the runner... then the runner is responsible for the execution.
In our case, simply creating a copy of the branch (git checkout -b new-branch-name) and making a new MR with the identical code allowed us to work around the issue. The new MR pipeline executed successfully.
In my case, I had made a typo on the filename and had forgotten to add a dot before it.
Please ensure the filename is .gitlab-ci.yml
How did I debug this?
On the GitLab UI, I went into CI/CD editor and couldn't see my file.

GitLab do not run CI/CD pipeline when creating new merge request

My GitLab CI/CD is run when I:
click Create merge request
every commit in created branch
when merge request branch is merged to master
I would like to skip first pipeline (on creating merge request), because I would like to optimize (fasten) my CI/CD.
On creating merge request new branch is created from master which already build successfully. There is no point of running the pipeline again.
Can I do that? I already check documentation for when but no idea how to solve this.
I often use the option Create branch instead of Create merge request. This can only be done in the issue view.
Then the first pipeline in this branch is running after the first push into the branch. With a push in the branch you can create a merge request.

Resources