Multiple versions of .gitlab-ci.yml in multiple branches - gitlab

If different branches in the repository have different .gitlab-ci.yml, then which would would be considered by the gitlab CI?

It is dependent on which branch you are pushing to (and how your gitlab-ci.yml file is setup.
For example:
When you are on a branch (say develop), and you push to develop, GitLab would build develop's gitlab-ci.yml file.
If you are on another branch (say feature), and you push to feature, GitLab would build feature's gitlab-ci.yml file.

Related

GitLab CI - separate environments deployment and semantic release

I am trying to follow GitLab flow with staging and production environments. I also want semantic-release plugin for both environments (with this I also need a branch for every environment so semantic-release could work, right?)
I have successfully made semantic-release working for staging branch, it creates vX.X.X-rc.x as expected and it also generates changelog. Great!
But how should I properly work with those branches? I think I understand how would I do that with only master branch and two environments, but I couldn't find any info about doing this with separate branches.
I create feature branch, finish feature, merge to master. Now what? Should I have deployment job, which on every merge to master automatically merges master to staging, runs semantic-release and then deploys it? And then have manual deployment which automatically merges staging to production, runs semantic-release and then deploys production?
And second think: how would I deal with forced commit message conventions? If I am merging feature to master, there is commit message feat(x): something something. But what should be in those automatic master to staging and staging to production merges?

gitlab-CI Efficiently fetching dependent git repos for CI jobs

I'm trying to set up a CI job that require dependent repositories to be placed along side the repository for which I'm enabling CI. By dependent, I mean that my main repo needs the code in the dependent repo but there is no build or test dependency between the two repos
I find a way to clone a dependent repository using this command in the job's script
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}#gitlab.mycompany.com/path_to_my/dependent_repo.git
The problem is that the repo is fresh cloned every time the job runs which takes way too long as the dependent repo is quite large.
Is there a way to "fetch" a dependent repo as efficiently as GitLab CI fetches its own repo (against which CI will run), basically performing a pull instead of a clone?
Should I use cache?
If you have one main repo that depend on a few other repos, I would add these as submodules. This makes it easier to handle in GitLab, and your colleagues can easily find the correct versions they need to clone for these repos. If you have some specific need to not have these as submodules, then I understand!
In GitLab, there are a few different ways of handling this. The most simple one is to use the GIT_STRATEGYvariable:
https://docs.gitlab.com/ee/ci/yaml/#git-strategy
You can set it to fetch like this:
my_job:
variables:
GIT_STRATEGY: fetch
script:
- echo test
GitLab will then try to reuse an existing working directory instead of always cloning a new one.
I had a case myself when I used a flag for git clone called --reference:
https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---reference-if-ableltrepositorygt
It has some very strange special cases that you have to think about. What the flag does is that git uses a local copy of a repository and copies objects from that one, instead of always copying from the network. This can greatly speed up cloning operations in some cases.
In addition to these suggestions, GitLab has a page with their suggestions to handle large repositories:
https://docs.gitlab.com/ee/ci/large_repositories/

Can I combine two branches into a GitLab CI build?

I know that GitLab CI will build each branch separately, but when I build the feature branch I want to compare some test results against the same tests on the master branch.
I could do that against the most recent build of master, or I'm happy to rebuild master on every feature branch commit if required.
Is that possible in GitLab CI?
You can use pipeline triggers to build your master branch during a feature branch pipeline.
In your case I guess you want to wait for the master pipeline to complete. This is not the default Gitlab behavior.
Using a script called pipeline-commander you can wait for the trigger to complete.

How can I use GitLab CI only?

I have repositories in BitBucket and I am satisfied and do not want to change it to another cvs.
But I want to use some free CI service for my projects.
Things I tried:
PhpCI, but PhpCI is bad supported
Jenkins, but it is too complicated for me
That's why I started researching Gitlab CI.
I saw that CI is a part of gitlab (https://about.gitlab.com/gitlab-ci/).
But maybe somehow I can use just CI and do not use another features.
Is it possible?
You can't use GitLab CI without GitLab, but no one forces you to use any of other GitLab features if you don't want to.
Git is distributed and you can have your source pushed to multiple destinations.
Just define it in your project's .git/config as another destination for push, for example:
[remote "origin"]
url = git#bitbucket.org:user/project.git
pushurl = git#bitbucket.org:user/project.git
pushurl = ssh://git#gitlab.yourdomain/user/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
Then add .gitlab-ci.yml, push, and GitLab CI will run, while your source will be both in BitBucket and GitLab (which you will use only for checking the CI pipeline).

How to trigger automatic build in gitlab CI on commit to non-default branch?

I have a project in GitLab that is integrated with Gitlab CI. Every push to master shedules a build of the project.
However, when a new branch is created and pushed into repository, build is not sheduled in gitlab CI. What are the settings for enabling build of other branches - alterativaly, how can i figure out what went wrong?
how can i figure out what went wrong?
Analyse .gitlab-ci.yml. Take a look at this, I would take a wild guess that you have limited your job execution with:
...
only:
- master
...

Resources