更新:UPDATE:如果我通过 REACT_APP_ENV ='username.cloudTech.com/api' npm脚本-它会成功传递此变量:If I pass REACT_APP_ENV='username.cloudTech.com/api' npm script - it passes this variable successfully:"scripts": { "start": "react-scripts start", "build": "react-scripts build", "build:staging": "REACT_APP_FRONT_APP_URL=nikonov91-dev.github.io/azure-flask-react/ npm run build" ...}然后瞧瞧. @OldPro的答案的更新.我引用了我的话:UPDATE on @OldPro`s answer.I've quoted my line:run: | cd front-app touch .env echo 'REACT_APP_DEV_SERVER_URL=${{ secrets.DEV_SERVER_URL }}' >> .env,但是在JS ch中,该值仍然为空: but the value is still empty in JS ch:我也尝试了@peterevans的答案I've tried also the answer of @peterevans run: | cd front-app echo "DEV_SERVER_URL=${{ secrets.DEV_SERVER_URL }}" >> $GITHUB_ENV touch .env echo "REACT_APP_DEV_SERVER_URL=${{ env.DEV_SERVER_URL }}" >> .env不幸的是,变量是相同的unfortunately the variable is the same更新 我确定我的方法有效,因为如果我在 YML 中对变量进行硬编码,则该变量可以正常工作,并且可以在我的Appv中轻松访问 I'm sure my approach is working because if I hardcode the variable in YML it works as should and can be easily accessed in my Appv - name: Store variables run: | cd front-app touch .env echo "REACT_APP_DEV_SERVER_URL='https://first-py-app.azurewebsites.net/'" >> .env和 this.API_BLOB_URL = process.env.REACT_APP_DEV_SERVER_URL +'api/blob/'; 变成 this.API_BLOB_URL =" https://first-py-app.azurewebsites.net/api/blob/" 但我仍在寻找解决方案,该方法如何从 GH-Secrets BUT I STILL LOOKING FOR solution how to pass variable from GH-Secrets推荐答案我发现有两种方法: 存储库秘密 可以设置设置-> 秘密-> 新存储库密码 Repository Secretsmay be set Settings->Secrets->New repository secret 环境秘密 可能会创建设置-> 环境-> 新环境-> 添加秘密 Environment Secretsmay be created Settings->Environments->New environment->Add secret并在工作描述中添加下一个参数:环境:您想要的环境与我的代码一样and add to job description next argument: environment: your-wanted-env as it is in my code 环境秘密在工作描述中需要其他参数:Environment Secrets needs additional argument in job description:jobs: trying-to-use-environment-secrets: runs-on: ubuntu-latest environment: test-env #<---The only difference we need to specify what environment to use for environment secrets steps: - name: Checkout uses: actions/checkout@v1 - name: Store variables run: | echo ${{ secrets.DEV_SERVER_URL_FROM_ENVIRONMENT_SECRETS }} echo "DEV_SERVER_URL=${{ secrets.DEV_SERVER_URL_FROM_REPOSITORY_SECRETS }}" 这篇关于无法访问环境机密变量,将其从GH页传递到ReactApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 13:18