我在 Golang 中撰寫了一個自定義操作,它有一個生成兩個輸出名稱的函式。
創建輸出名稱以供以后在作業流中使用,因此我可以在一個作業(“計算版本”)中呼叫該操作,捕獲輸出名稱,并在另一個作業中使用它(“構建”)
用于創建輸出名稱的操作中的 Go 函式是:
func SetTag(value string){
fmt.Printf(`::set-output name=repo_tag::%s`, value)
fmt.Printf(`::set-output name=ecr_tag::%s`, "v" value)
}
使用上述輸出的作業流程如下:
Version:
name: Calculate Version
runs-on: ubuntu-latest
outputs:
repo_version_env: ${{ steps.version.outputs.repo_tag }}
ecr_version_env: ${{ steps.version.outputs.ecr_tag }}
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Calculate version
id: version
uses: my_custom_action/version@v1
Build:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Build
run: |
echo ${{ needs.Version.outputs.ecr_version_env }}
echo ${{ needs.Version.outputs.repo_version_env }}
當我運行作業流時,回顯命令在操作構建輸出中為我提供以下資訊:
1 echo
2 echo v1.4.1::set-output name=ecr_tag::1.4.1
代替:
1 echo v1.4.1
2 echo 1.4.1
我究竟做錯了什么?
如果有更好的方法來使用從動作輸出的變數,在作業流中的不同作業之間,我也會很高興聽到。
非常感謝。
uj5u.com熱心網友回復:
對于我在這里測驗的內容,問題是 go 函式將列印如下資料:
::set-output name=repo_tag::1.4.1::set-output name=ecr_tag::v1.4.1%
這個問題似乎與你沒有打破界限的事實有關。
它應該通過將 Go 函式更新為:
func SetTag(value string){
fmt.Printf(`::set-output name=repo_tag::%s`, value)
fmt.Print("\n")
fmt.Printf(`::set-output name=ecr_tag::%s`, "v" value)
fmt.Print("\n")
}
請注意,第二個fmt.Print("\n")將洗掉%終端上的符號。
如果你想檢查我所做的測驗:
