Home > Blockchain >  Gitlab CI - set variable using export
Gitlab CI - set variable using export

Time:08-31

I have the following URL:

NEW_URL = google.com/parentproject/subproject/ccc.git

echo $NEW_URL | rev | cut -d"/" -f1  | rev | cut -c -3
ccc

above command works perfectly fine but when I say

export DIR="$(NEW_URL | rev | cut -d"/" -f1 | rev | cut -c -3)"

I get No such file or directory error.. I tried to use escape characters around pipe delimiter but I did not get the result and only error.. I am trying to fetch ccc out of that url and export it to another variable ... Can somebody please help me?

NOTE: I am using this in Gitlab CI and trying to fetch the directory name between last / and .git

CodePudding user response:

You need to use echo $NEW_URL instead of just $NEW_URL. As written, your code is:

google.com/parentproject/subproject/ccc.git | rev | cut ...

instead of

echo google.com/parentproject/subproject/ccc.git | rev | cut ...

so bash is trying to run google.com/parentproject/subproject/ccc.git as a command, which does not exist as per your error message.

As a side note, you can do what you are trying to accomplish with basename:

$ filename=$(basename ${NEW_URL})
$ echo ${filename}
ccc.git
$ cutname="${filename%.*}"
$ echo ${cutname}
ccc
  • Related