简体   繁体   English

Gitlab CI - 使用导出设置变量

[英]Gitlab CI - set variable using export

I have the following URL:我有以下 URL:

NEW_URL = google.com/parentproject/subproject/ccc.git 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)"导出 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?我得到没有这样的文件或目录错误..我尝试在 pipe 分隔符周围使用转义字符,但我没有得到结果,只有错误..我试图从 url 中获取 ccc 并将其导出到另一个变量...有人能帮帮我吗?

NOTE: I am using this in Gitlab CI and trying to fetch the directory name between last / and.git注意:我在 Gitlab CI 中使用它并尝试获取最后一个 / 和.git 之间的目录名称

You need to use echo $NEW_URL instead of just $NEW_URL .您需要使用echo $NEW_URL而不仅仅是$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.所以 bash 正在尝试将google.com/parentproject/subproject/ccc.git作为命令运行,根据您的错误消息,该命令不存在。

As a side note, you can do what you are trying to accomplish with basename :作为旁注,您可以使用basename完成您想要完成的工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM