A
A
Adel Khalitov2020-02-01 01:01:38
bash
Adel Khalitov, 2020-02-01 01:01:38

What do gitlab-ci scripts mean?

I read other people's runners and I can't understand what they mean, please help me decipher.

What does | , cut -d'/' -f2?

- export SUBDOMAIN=$(echo $CI_COMMIT_REF_NAME | cut -d'/' -f2)


What does fi mean?
export LINK=$(if [ $CI_JOB_NAME = "Run with DB" ]; then echo $SUBDOMAIN; else echo "master"; fi)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Shitskov, 2020-02-01
@adelkhalitov

linux.yaroslavl.ru/docs/conf/gnu-util/bash/bash_ug...

V
Vadim Priluzkiy, 2020-02-01
@Oxyd

Let me fill in the gaps to make it clearer...

export SUBDOMAIN=$(echo $CI_COMMIT_REF_NAME  |  cut -d'/' -f2)

export SUBDOMAIN -- make the SUBDOMAIN variable "global", that is, it will persist even after the script ends (but only until the shell session ends).
Everything between $( ) is umm... a literal resulting from sequentially processing the value of the $CI_COMMIT_REF_NAME variable.
In short, the esho utility simply prints the value of the $CI_COMMIT_REF_NAME variable to the screen. Operator | we force it not to print on the screen, but to pass it to the input of the cut utility, from the GNU coreutils kit (if my sclerosis does not bug me) cut can cut lines according to certain rules. mancut:
echo $CI_COMMIT_REF_NAME | cut -d'/' -f2

cut - remove sections from each line of files
SYNOPSIS
cut OPTION... [FILE]...
DESCRIPTION
Print selected parts of lines from each FILE to standard output.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-b, --bytes=LIST
select only these bytes
-c, --characters=LIST
select only these characters
-d, --delimiter=DELIM
use DELIM instead of TAB for field delimiter
-f, --fields=LIST
select only these fields; also print any line that contains no de-
limiter character, unless the -s option is specified
-n (ignored)
--complement
complement the set of selected bytes, characters or fields
-s, --only-delimited
do not print lines not containing delimiters
--output-delimiter=STRING
use STRING as the output delimiter the default is to use the input
delimiter
-z, --zero-terminated

cut -- reads lines (in your case, most likely one line), uses the character / as a separator between fields, and prints only the second field as a result. That is, if you do this:
echo "a/bb/cc/d" | cut -d'/' -f2  #то на выходе мы получим строку bb

Here's what it looks like in practice.
kpFoxAx.png
This is the answer to question number 1 ;-)
The answer to question number two ... However, you will understand everything yourself now, when I turn a one-line into a multi-line ...
export LINK=$(if  [ $CI_JOB_NAME = "Run with DB" ]; 
                            then 
                               echo $SUBDOMAIN; 
                         else 
                               echo "master"; 
                        fi)

Now it is clear what fi is? It's just the closing parenthesis to the if. -- if vice versa, or fin ;-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question