首页 > 解决方案 > Github Actions:如何为多个作业创建多行环境变量

问题描述

我想将几行添加到代码文件中。这在各种工作中。所以我创建了一个创建文本文件并上传的作业。

create_file:
  runs-on: ubuntu-latest
  steps:      
    - shell: bash
      run: |
        cat << EOF > data.txt
        A = "..."
        B = "..."
        C = "..."
        ...
        EOF
    - name: Create data file
      uses: actions/upload-artifact@1
      with:
        name: configuration
        path: data.txt

在下一项工作中,我上传文件并希望将此行附加到代码文件中。

test_file:
  runs-on: ubuntu-latest
  needs: [create_file]
  steps:
  - name: Download file     
    uses: actions/download-artifact@v1
    with:
      name: configuration
      path: configuration/data.txt
  - shell: bash
     run: |
       cat configuration/data.txt >> main.py
       python main.py

我的问题是第二个作业太快了,在data.txt文件上传之前搜索文件,以及如何处理附加内容。每行的命令echo "..." >> main.py会很烦人。

更新: 现在我得到data.txt以下错误消息的工作:

 Download action repository 'actions/upload-artifact@1'
 ##[warning]Failed to download action 'https://api.github.com/repos/actions/upload-artifact/tarball/1'. Error Response status code does not indicate success: 404 (Not Found).
 ...
 ##[error]Response status code does not indicate success: 404 (Not Found).

标签: githubcontinuous-integrationyamlgithub-actions

解决方案


这个错误非常愚蠢。该行actions/upload-artifact@1应该是actions/upload-artifact@v1.


推荐阅读