Trigger a new pipeline on merge request creation in gitlab-ci - gitlab

i have a mono repo structure and created a pipeline that only runs for specific sub folders which have changed.
Now if i change something in Context1 and the pipeline does not succeed, and then change something in Context2 and the pipeline succeeds, a created merge request would say it is mergeable because the last pipeline succeeded.
How can i trigger a new pipeline on a merge request that runs the pipeline that runs for all sub folders? (Not asking how to create such a pipeline, only how to trigger one)

Related

Azure pipeline on PR validate file before merging to master branch

I have master branch which has multiple yaml files. Every file on update will be pushed to feature/{filename.yaml} and with PR will be merged to master branch.
But before merging I need to validate that file from feature has valid YAML syntax.
If syntax is not valid build will fail and not be merged to master branch.
But if everything is ok I need to send content of yaml file to API endpoint, and then merge it to master branch.
Thanks
You can use Files Validator task to validate file.
[

how to pass git commit message from parent to child pipeline in gitlab?

I have a commit message stored in /tmp/message file in parent's pipeline and I would like to send the contents of this file to the child pipeline in Gitlab. Can someone help me how I can do this using yml pipelines?
One approach is to use a cache (as seen here), or rather an artifact (as seen here), in order to store that message content in a file.
The idea is to share a file (artifact) or key/value (cache) between jobs.

GitLab - Update private project dependent on public project

Assuming that there is a public project publicProject. And you have got your own private Project privateProject.
Is there a way to automatically trigger a CI/CD pipeline wihin privateProject every time publicProject receives a new push? Note, that although publicProject is public, there is no way to modify the pipeline within publicProject - so no trigger would be possible.
Are there any chances this could be possible?
If no trigger is possible, you might need, as a workaround, to schedule your own pipline (see "Configuring pipeline schedules") in order to:
pull the public repository
check if new commits have been done
The last fetched commit could be cached (see Caching in GitLab CI/CD) in a file which can persists between subsequent jobs.

Why the production plan job in to-be-continuous/terraform is launched on a merge request pipeline?

I'm wondering why the job "tf-plan-production" in the to-be-continuous/terraform template is the only one running on a merge request pipeline?
Does anybody know the reason behind this?
Because I find it disturbing to have 2 pipelines, 1 detached pipeline containing only a single job while the other pipeline contains all the other jobs (tf-plan-review, tf-tflint, tf-checkov ...). I hesitate to override this rule as I may miss something important.
To be more precise, in this to-be-continuous template, all the defined jobs are never run on a merge request pipeline by using the rule :
# exclude merge requests
- if: $CI_MERGE_REQUEST_ID
when: never
Except the "tf-plan-production" job which have the rule:
# enabled on merge requests
- if: $CI_MERGE_REQUEST_ID
terraform plan is a nondestructive operation that compares what terraform would create to what exists in output, and creates a diff between existing state and state that has been coded but not created.
Typically it is run when a PR is created so that a dry run is available and visible to the developers, while terraform apply is run on merge. If there isn't another environment developers can test their changes in, it is a necessary step.

Gitlab - run script after create branch

Is there any option to execute script after branch command: 'git branch new123? If user will create new branch I would like to auto checkout into new branch and auto create folder 'new123' with branch name and two other folder inside this folder like 'int', 'ext'.
You would need:
either a GitLab webhook, that is a listener on a server you control, which would receive JSON push events from GitLab, and, when detecting a new branch, would perform the operations you describe in a local clone of the repository.
or a GitLab-CI job which can run on every push, and whose job would check if that push is a new branch, before doing the same operation in its workspace (so on GitLab side rather than on a private server like a webhook does)

Resources