【发布时间】:2020-02-03 03:27:09
【问题描述】:
在我的action.yml 中我定义了一个输入:
name: 'test action'
author: Param Thakkar
description: 'test'
inputs:
test_var:
description: 'A test variable'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
在我的工作流程中,我通过了 test_var:
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Test the GH action
uses: paramt/github-actions-playground@master
with:
test_var: "this is just a test"
所以应该有一个在工作流运行时创建的环境变量,对吧?但是当我运行这个简短的 python 脚本时:
import os
print(os.getenv('TEST_VAR'))
print("It works!")
exit(0)
打印出来:
None
It works!
我认为我必须通过我的 Dockerfile 传递 ENV 变量...现在我的 Dockerfile 看起来像这样:
FROM python:latest
# Add files to the image
ADD entrypoint.py /entrypoint.py
ADD requirements.txt /requirements.txt
# Save ENV var in a temp file
RUN $TEST_VAR > /temp_var
# Install dependencies and make script executable
RUN pip install -r requirements.txt
RUN chmod +x entrypoint.py
RUN echo "temp var: "
RUN cat /temp_var
# Run script with the ENV var
ENTRYPOINT export TEST_VAR="$TEST_VAR"; /entrypoint.py
但是变量没有回显,也没有传递给 pythons 脚本。我错过了什么吗?当我尝试将我的$TEMP_VAR 设置为随机字符串时,它被 发送到Python 脚本。这是代表我的错误还是 GitHub 操作未按预期工作?
【问题讨论】:
-
您是如何访问 Dockerfile 中 action.yml 中定义的输入参数的?我正在尝试做同样的事情,但我遇到了一些麻烦。
标签: docker dockerfile github-actions