DEV Community

Cover image for GitLab Pipeline Annoyances
Felicia Walker
Felicia Walker

Posted on • Edited on

GitLab Pipeline Annoyances

I used GitLab build pipelines in a previous position where I refactored two files with a complex layout of jobs and functionality. While trying to simplify the flow and reduce the amount of copied code, I ran into a number of annoyances. Some were due to wanting more programming concepts that are not supported but others were basic functionality. I also ran into some items that did not work even though the documentation indicated that they should.

I'd like to gripe about these, but also offer the solutions I came up with in case others also run into these issues.

Disclaimer
I do not have the original files to refer to, but have only written about things I feel I remember well.

Visualization

Lack of connection lines

You think there should be connecting lines between your stages, but frequently there is nothing. The problem is that most of this is figured out at runtime, so nothing can be shown in the visualization. Only links specified by needs or depends are defined ahead of time and can be shown.

Here is a forum post about this.

No visualization when using other branches

If your pipeline has any includes that are on a branch other than main, you do not get any visualization. There is not much to say about this, unfortunately. The visualization in general doesn’t seem to handle includes very well.

Variables

Changing global variables

You cannot directly change global variables from a job once they are defined and set. Instead, you will need to make a step to change the values in a bash script then save as a dotenv artifact. Once saved, the values will be automatically be available to any future steps.

Here is a forum post with an example.

Predefined variables not going to child pipelines

The standard predefined CI/CD variables are not available to child pipelines by default. It seems like they should just be available everywhere, but alas no. If you want to use any of these, you will need to define and pass them in the child pipeline step like any other variable you want to pass.

Shell Scripting

Issues with echos and colons

Putting a colon in any echo statements can cause Gitlab to interpret it as actual syntax, leading to a syntax error. It appears to be an issue with the YAML parsing, not Gitlab itself.

You can try quoting the whole string, but be careful if you are mixing quote styles. There are some other suggestions using templates, in case that does not work.

Multiline echos

An echo with a multi line quoted string may work if this is the only command, but once you use “>” or “|” for a multi step script, this fails. In this case, the additional lines in the echo string are interpreted as another script command.

I never found a good way around this except to split the long string and use multiple echo commands.

When to use braces around a variable

This was never clear to me since many examples usually do not use braces around a variable, both outside of script sections or within them. However, some do put braces around. I always tried to use the braces, but sometimes they seemed to cause problems.

It appears that you cannot use braces unless some text immediately follows the variable. In this case, the braces explicitly group the variable name away from the other text. Here is a post about this with some examples.

Some Good References

Here are some good references I came across trying to figure some of these things out:

Top comments (0)