相关疑难解决方法(0)

如何使用 python 在 GitHub actions 中设置环境变量

我想执行一个 python 脚本来在 GitHub actions 中设置一些环境变量。我想稍后在 GitHub 操作步骤中使用这些环境变量。我的 python 脚本如下所示:

new_ver = get_version_from_commit(commit_msg)
if new_ver:
    if new_ver == "false":
        os.environ["SHOULD_PUSH"] = "0"
        print("Not pushing the image to k8s")
        exit(0)
    else:
        new_tag = app_name + ":" + str(new_ver)
        os.environ["DOCKER_IMAGE_TAG"] = new_tag
        os.environ["SHOULD_PUSH"] = "1"
        print("New tag: " + new_tag)
        exit(0)
Run Code Online (Sandbox Code Playgroud)

执行上述 python 脚本后,我的 GitHub 操作文件的一部分如下所示:

- name: Print env var
  run: echo ${{ env.DOCKER_IMAGE_TAG }}
- name: Build and push
  id: docker_build
  uses: docker/build-push-action@v2
  with:
     push: true
     tags: ${{ secrets.DOCKER_REGISTRY }}/${{ …
Run Code Online (Sandbox Code Playgroud)

python continuous-integration environment-variables github-actions

15
推荐指数
1
解决办法
1万
查看次数