Adding custom .gitlab-ci.yml files? - gitlab

I can see that GitLab supports various templates for things such as licenses, issue templates and such, but I can't seem to find a way to add a template for .gitlab-ci.yml files. Can this be done on Gitlab CE?

No, unless you can contribute (through merge request) to the gitlab-org/gitlab-ci-yml project, which is a collection of useful .gitlab-ci.yml templates.
Then, it is possible the API allows you to query that new template:
See CE Get GitLab CI YML templates
For one template:
curl https://gitlab.example.com/api/v4/templates/gitlab_ci_ymls/Ruby

Related

Is there a way to override the default GitLab CI AutoDevOps templates?

I am running my GitLab CI pipelines in an offline environment with none of my repositories containing the pipeline YAML files. Due to the sheer number of repositories I enabled AutoDevOps to use a baseline image until I can define pipelines for each specific repository as necessary, however, the application dependencies and pipeline images cannot be downloaded. I have a means to resolve this, but it requires configuration in the .gitlab-ci.yml file meaning the default AutoDevOps templates cannot be used and I have to make changes in every single repository, defeating the point of enabling AutoDevOps in the first place.
Is there a way to override the default AutoDevOps templates with my own?
From the documentation :
Auto DevOps is completely customizable because the Auto DevOps
template is just an implementation of a .gitlab-ci.yml file.
So AutoDevOps pipelines are only .gitlab-ci.yml files and you need to include them to overrides jobs and anything in this pipeline. You need to include a .gitlab-ci.yml file to override the default.
AutoDevOps is useful even if you include a ci file because it add a lot of jobs without writing them.

How to import a yml file based on condition?

Present we kept multiple pipelines in separate yml files and all of them are included in the mail ci yml file.
using include statements.
Is there anyway to make it conditional.
Like I will have pipeline1 and pipeline2 yaml files.
So I can create another pipeline.yml where I can choose among the above two files based on some condition.
Gitlab is designed for deterministic pipelines, all other solutions add-on that looks implicit.
Web service
Include in .gitlab-ci.yml link to the web server, which could be a dynamically generated yml file.
include:
- 'https://your-service.com/gitlab-ci-generate'
Unfortunately, It's not possible to use CI variables in link to server. gitlab issue link
Dynamic child pipelines
You have complete control of the pipeline. Write a simple bash script, which renames your pre-pushed .yml files and executes that pipeline.

Using Gitlab CI from a submodule

I'm trying to "mutualize" my CI.
I have a lot of project that use basically the same gitlab-ci.yml.
I was thinking about creating a git submodule containing the gitlab-ci.yml that all my project are using, in which I could inject env variable in order to make it generic so I could re-use it in my futur projects.
My problem is that I don't see any documentation about this so I was wondering :
Is it possible ? And if yes, how can I tell gitlab to use the gitlab-ci.yml that is inside of this submodule ?
If it's a bad idea, do you have any idea of the correct way to do this ?
Thanks !
What you're looking for are Gitlab CI template files, that can be include'd in other .gitlab-ci.yml files.
You can check out the documentation for include here.
Example :
# .gitlab.ci.yml
include:
- 'https://gitlab.com/awesome-project/raw/main/.before-script-template.yml'
- '/templates/.after-script-template.yml'
This includes CI files with default variables, stages, workflows that can be overriden anywhere in your other CI files. This brings the genericity you need.

How to create a common pipeline in GitLab for many similar projects

We have hundreds of similar projects in GitLab which have the same structure inside.
To build these projects we use a one common TeamCity build. We trigger and pass project GitLab URL along with other parameters to the build via API, so TeamCity build knows which exact project needs to be fetched/cloned. TeamCity VCS root accepts target URL via parameter.
The question is how to replace existing TeamCity build with a GitLab pipeline.
I see the general approach is to have CI/CD configuration file(.gitlab-ci.yml) directly in project. Since the structure of the projects the same this is not the option to duplicate the same CI/CD config file across all projects.
I'm wondering is it possible to create a common pipeline for several projects which can accept the target project URL via parameter ?
You can store the full CICD config in a repository and put in all your projects a simple .gitlab-ci.yml which includes the shared file.
With thus approach there is no redundant definition of the jobs.
Still, you can add specific other jobs to specific projects (in the regarding .gitlab-ci.yml files or define variables in a problem and use some jobs conditionally) - you can also include multiple other definition files, e.g. if you have multiple similar projects.
cf. https://docs.gitlab.com/ee/ci/yaml/#include
With latest GitLab (13.9) there are even more referencing methods possible: https://docs.gitlab.com/ee/ci/yaml/README.html#reference-tags
As #MrTux already pointed out, you can use includes.
You can either use it to include a whole CI file, or to include just certain steps. in Having Gitlab Projects calling the same gitlab-ci.yml stored in a central location - you can find detailed explanation with examples of both usages

What's the purpose of azure-pipeline.yml

I have read some tutorials about Azure DevOps. There are 3 things i do not really understand:
Can we say azure-pipeline.yml on Azure is the equivalent of .gitlab-ci.yml on gitlab ?
I have read some tutorials talking about azure-pipeline.yml files and others talking about azure-pipelines.yml ? What is the good syntax for this file name ?
I have create a "devops project" from Azure Services page. I have choose ASP.Net Core Application and Windows Web App. I can see a pipeline on dev.azure.com but there is no yml file in source code. So i am wondering where is this file...
Thanks
Can we say azure-pipeline.yml on Azure is the equivalent of .gitlab-ci.yml on gitlab
YAML defines the way to code your configuration management by defining build and release pipelines in the code.It is named as azure-pipelines in Azure Devops and .gitlab-ci.yml on gitlab
have read some tutorials talking about azure-pipeline.yml files and others talking about azure-pipelines.yml ? What is the good syntax for this file name ?
azure-pipelines.yml is the default name, but if you need you canhange the name of the yaml file by clicking on "Edit in the visual designer".
I have create a "devops project" from Azure Services page. I have choose ASP.Net Core Application and Windows Web App. I can see a pipeline on dev.azure.com but there is no yml file in source code. So i am wondering where is this file...
There are two ways to create the pipeline one is using the classic editor and using the YAML code. It should definitely be there if you create it using YAML
Answering your question in the same order they were asked.
Yes, azure-pipeline.yml is the equivalent of gitlab-ci.yml. In both cases you bundle together a number of commands you want to execute.
It is the same. The file is called azure-pipelines.yml. Good thing if you try to edit the file in azure-devops is that there is a really nice check and auto-completion tool, that helps a lot especially in indentation (spaces before the command)which is a common issue with yaml files.
If you created the Ci/CD pipelines by the development center in azure portal you see a UIed version of the yaml. But for every step you can still see the yaml code if you wish. If you try to create a new build pipeline the default way you get is to use the yaml file.

Resources