GitHub Actions获取一个作业的输出并传递给矩阵作业

huangapple go评论47阅读模式
英文:

Github Actions get output fom one job to matrix job

问题

I have translated the code part for you as requested. Here is the translated code:

all.

I have this pipeline. Where I just basically want to get changed filed dirs and run helm push command on that dirs. 

name: Helm Package and Push
on:
  push:
    branches:
      - chartChange
    paths:
    - 'charts/**'
jobs:
  detect_changes:
  runs-on: ubuntu-latest
    outputs:
      list: ${{ steps.changed-files-specific.outputs.all_changed_files }}

steps:
  - name: Checkout
    uses: actions/checkout@v2
  
  - name: Get changed files in the docs folder
    id: changed-files-specific
    uses: tj-actions/changed-files@v35
    with:
      json: true
      files: charts/**  # Alternatively using: `docs/**` or `docs`
  
  - name: Run bash script
    run: |
            for i in ${{ steps.changed-files-specific.outputs.all_changed_files }}; do echo ${i%/*}; done

Test_from_first_job:
  needs: detect_changes
  runs-on: ubuntu-latest

strategy:
      matrix:
        folders: ${{fromJson(needs.detect_changes.outputs.list)}}

steps:
  - name: Checkout
    uses: actions/checkout@v2
  
  - name: Run test step  
    run: |
            echo ${{matrix.folders}}

I hope this helps. If you have any other questions or need further assistance, please let me know.

英文:

all.

I have this pipeline. Where I just basically want to get changed filed dirs and run helm push command on that dirs.

name: Helm Package and Push
  on:
    push:
      branches:
        - chartChange
      paths:
      - 'charts/**'
jobs:
  detect_changes:
  runs-on: ubuntu-latest
    outputs:
      list: ${{ steps.changed-files-specific.outputs.all_changed_files }}


steps:
  - name: Checkout
    uses: actions/checkout@v2
  
  - name: Get changed files in the docs folder
    id: changed-files-specific
    uses: tj-actions/changed-files@v35
    with:
      json: true
      files: charts/**  # Alternatively using: `docs/**` or `docs`
  
  - name: Run bash script
    run: |
      for i in ${{ steps.changed-files-specific.outputs.all_changed_files }}; do echo ${i%/*}; done

  Test_from_first_job:
  needs: detect_changes
  runs-on: ubuntu-latest

strategy:
      matrix:
        folders: ${{fromJson(needs.detect_changes.outputs.list)}}

steps:
  - name: Checkout
    uses: actions/checkout@v2
  
  - name: Run test step  
    run: |
      echo ${{matrix.folders}}

But however my jobs failing with this error:

Error when evaluating 'strategy' for job 'Test_from_first_job'. .github/workflows/cm- 
push.yml (Line: 37, Col: 22): Error parsing fromJson,.github/workflows/cm-push.yml 
(Line: 37, Col: 22): Unexpected character encountered while parsing value: \. Path '', 
line 1, position 1.,.github/workflows/cm-push.yml (Line: 37, Col: 22): Unexpected type 
of value '', expected type: Sequence.

Any ideas how can i make it work ?

REgards

答案1

得分: 1

矩阵必须能够在模板解析时扩展,不能依赖于任何运行时定义的值。

您需要依赖于一个脚本来触发另一个工作流,并将值作为参数传递。参数值在解析时可用的,因此可以用来启动矩阵。

或者您必须使用运行时解决方案来循环遍历值,比如使用脚本块和for循环。

英文:

The matrix must be able to expand at the time the template is parsed and it can't rely on any runtime-defined values.

You'll need to rely on a script to trigger another workflow and pass the value in as a parameter. The parameter value IS available at parse time, so that can be used to spin up the matrix.

Or you must loop through the values using a runtime solution, such as a script block and a for-loop.

huangapple
  • 本文由 发表于 2023年2月8日 19:48:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定