Gitlab-ci
st1:
stage: build
before_script:
- |
function curling()
{
echo "ip are $1"
}
script:
- foo=$(curl x socks5 ifconfig.co) # like get proxy ext ip
- boo=$(curl ifconfig.co) # like get my ext ip
- |
if [ $foo -eq $foo ]
then
curling equal
else
curling not_equal
fi
when: manual
only:
- master
tags:
- tag
我想將作業數量增加到 3 個并在其中使用相同的功能。我可以定義一個函式并在不同的作業中使用它嗎?
喜歡
stages:
-st1
-st2
-st3
st1:
stage: st1
script:
- |
function curling()
{
echo "ip are $1"
}
st2:
stage: st2
script:
- foo=$(curl x socks4 ifconfig.co) # like get first proxy ext ip
- boo=$(curl ifconfig.co) # like get my ext ip
- |
if [ $foo -eq $foo ]
then
curling equal
else
curling not_equal
fi
when: manual
only:
- master
tags:
- tag
st3:
stage: st3
script:
- foo=$(curl x socks5 ifconfig.co) # like get second proxy ext ip
- boo=$(curl ifconfig.co) # like get my ext ip
- |
if [ $foo -eq $foo ]
then
curling equal
else
curling not_equal
fi
when: manual
only:
- master
tags:
- tag
這樣做的目的是使用許多動作并通過具有相同模板的 echo/curl/webhook 訊息報告其結果,其中幾個詞不同,并且不要多次重復相同的模板
uj5u.com熱心網友回復:
聽起來像 YAML Anchors 是你的答案(gitlab 檔案)
.shared_curl_tmp: &shared_curl
- |
if [ $foo -eq $foo ]
then
curling equal
else
curling not_equal
fi
stages:
-st1
-st2
-st3
st1:
stage: st1
script:
- |
function curling()
{
echo "ip are $1"
}
st2:
stage: st2
script:
- foo=$(curl x socks4 ifconfig.co) # like get first proxy ext ip
- boo=$(curl ifconfig.co) # like get my ext ip
<<: *shared_curl
when: manual
only:
- master
tags:
- tag
st3:
stage: st3
script:
- foo=$(curl x socks5 ifconfig.co) # like get second proxy ext ip
- boo=$(curl ifconfig.co) # like get my ext ip
<<: *shared_curl
when: manual
only:
- master
tags:
- tag
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/330818.html
