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

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

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:

  1. all.
  2. I have this pipeline. Where I just basically want to get changed filed dirs and run helm push command on that dirs.
  3. name: Helm Package and Push
  4. on:
  5. push:
  6. branches:
  7. - chartChange
  8. paths:
  9. - 'charts/**'
  10. jobs:
  11. detect_changes:
  12. runs-on: ubuntu-latest
  13. outputs:
  14. list: ${{ steps.changed-files-specific.outputs.all_changed_files }}
  15. steps:
  16. - name: Checkout
  17. uses: actions/checkout@v2
  18. - name: Get changed files in the docs folder
  19. id: changed-files-specific
  20. uses: tj-actions/changed-files@v35
  21. with:
  22. json: true
  23. files: charts/** # Alternatively using: `docs/**` or `docs`
  24. - name: Run bash script
  25. run: |
  26. for i in ${{ steps.changed-files-specific.outputs.all_changed_files }}; do echo ${i%/*}; done
  27. Test_from_first_job:
  28. needs: detect_changes
  29. runs-on: ubuntu-latest
  30. strategy:
  31. matrix:
  32. folders: ${{fromJson(needs.detect_changes.outputs.list)}}
  33. steps:
  34. - name: Checkout
  35. uses: actions/checkout@v2
  36. - name: Run test step
  37. run: |
  38. 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.

  1. name: Helm Package and Push
  2. on:
  3. push:
  4. branches:
  5. - chartChange
  6. paths:
  7. - 'charts/**'
  8. jobs:
  9. detect_changes:
  10. runs-on: ubuntu-latest
  11. outputs:
  12. list: ${{ steps.changed-files-specific.outputs.all_changed_files }}
  13. steps:
  14. - name: Checkout
  15. uses: actions/checkout@v2
  16. - name: Get changed files in the docs folder
  17. id: changed-files-specific
  18. uses: tj-actions/changed-files@v35
  19. with:
  20. json: true
  21. files: charts/** # Alternatively using: `docs/**` or `docs`
  22. - name: Run bash script
  23. run: |
  24. for i in ${{ steps.changed-files-specific.outputs.all_changed_files }}; do echo ${i%/*}; done
  25. Test_from_first_job:
  26. needs: detect_changes
  27. runs-on: ubuntu-latest
  28. strategy:
  29. matrix:
  30. folders: ${{fromJson(needs.detect_changes.outputs.list)}}
  31. steps:
  32. - name: Checkout
  33. uses: actions/checkout@v2
  34. - name: Run test step
  35. run: |
  36. echo ${{matrix.folders}}

But however my jobs failing with this error:

  1. Error when evaluating 'strategy' for job 'Test_from_first_job'. .github/workflows/cm-
  2. push.yml (Line: 37, Col: 22): Error parsing fromJson,.github/workflows/cm-push.yml
  3. (Line: 37, Col: 22): Unexpected character encountered while parsing value: \. Path '',
  4. line 1, position 1.,.github/workflows/cm-push.yml (Line: 37, Col: 22): Unexpected type
  5. 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:

确定