提问人:Ashar 提问时间:10/30/2023 最后编辑:Ashar 更新时间:10/30/2023 访问量:36
如何在单独的工作流2中从工作流1中读取变量的值
How to read value of variable from workflow1 in a separate workflow2
问:
我有一个调用方工作流,它调用了 2 个工作流(workflow1 和 workflow2),如下所示:mytech/DevOps/.github/workflows/caller.yml@myfeature
name: newCICD - AD
on:
workflow_dispatch:
jobs:
BUILD:
uses: mytech/DevOps/.github/workflows/workflow1.yml@myfeature
with:
zipfile: 'myweb.war'
secrets: inherit
DEPLOY: <---- need condition for this job
needs: [BUILD]
if: "${{ needs.BUILD.outputs.finalpath != '' }}"
uses: mytech/DevOps/.github/workflows/workflow2.yml@myfeature
with:
runner_name: ${{ needs.setvars.outputs.runner_name }}
gotbuildurl: "${{ needs.BUILD.outputs.finalpath }}"
secrets: inherit
cat mytech/DevOps/.github/workflows/workflow1.yml
on:
workflow_call:
inputs:
zipfile:
required: true
default: ''
type: string
outputs:
finalpath: "{{ jobs.job1.outputs.output1 }}"
jobs:
job1:
outputs:
output1: ${{ steps.step1.outputs.some_output }}
runs-on: windows-latest
steps:
- name: Step 1
id: step1
run: |
$fileToCheck = "${{ inputs.zipfile }}"
#Check if the file exists
if (Test-Path $fileToCheck -PathType Leaf) {
echo "some_output=123" >> "$env:GITHUB_OUTPUT"
}
我只想在 from workflow1.yml 的变量不为空或 inputs.zipfile 不为空时调用 job。DEPLOY
mytech/DevOps/.github/workflows/workflow2.yml@myfeature
output1
job1
我尝试将变量导出为从作业中使用,并尝试在作业中读取和设置条件。output1
finalpath
outputs
BUILD
DEPLOY
但是,我收到以下错误:
无效的工作流文件:.github/workflows/caller.yml#L36
工作流无效。在 .github/workflows/caller.yml 中(行:36, 列:11):调用的工作流出错 mytech/DevOps/.github/workflows/workflow1.yml@myfeature(行:121, 列:25):意外值 '{{ jobs.job1.outputs.output1 }}
恳请建议。
答: 暂无答案
评论
{{ jobs.job1.outputs.output1 }}
${{ jobs.job1.outputs.output1 }}
value
$
Invalid workflow file: .caller.yml#L36 The workflow is not valid. In .github/workflows/main.yml (Line: 36, Col: 11): Error from called workflow mytech/DevOps/.github/workflows/workflow1.yml@myfeature (Line: 121, Col: 25): Unrecognized named-value: 'jobs'. Located at position 1 within expression: jobs.job1.outputs.output1 In .github/workflows/main.yml (Line: 36, Col: 11): Error from called workflow mytech/DevOps/.github/workflows/workflow1.yml@myfeature (Line: 121, Col: 25): Unexpected value '${{ jobs.job1.outputs.output1 }}