我正在尝试使用 gitlab CI 管道动态设置环境变量。我想要实现的是根据我部署到的阶段(阶段、产品)注入正确的 API 密钥和 URL。
在我的 React 应用程序中,我使用react 文档process.env.REACT_APP_APPSYNC_URL中描述的方法访问变量。
到目前为止,我已经尝试在gitlab UI 中设置变量并在我的.gitlab-ci.yml文件中引用它们(见下面的代码)。
不幸的是,我无法以这种方式访问变量,因此我将非常感谢您的帮助。
我刚刚开始使用 CI/CD 和不同的环境,所以如果我通常在这里使用不好的方法,请告诉我!
这是 .gitlab-ci.yml:
image: nikolaik/python-nodejs:latest
stages:
- install
- test
- deploy
install:
stage: install
script:
- npm install
- npm run build
artifacts:
untracked: true
only:
- stage
- master
test:
stage: test
dependencies:
- install
script:
- npm run test
artifacts:
untracked: true
only:
- stage
- master
deployDev:
stage: deploy
only:
- stage …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用 useEffect 挂钩中 apollo v3 的 useSubscription 挂钩来更新 GraphQL 订阅:
let containerSubscription = useSubscription<CreatedDateSubscription, CreatedDateSubscriptionVariables>(
gql(containerUpdatedOnCreatedDate),
{
variables: { createdDate: selectedDate },
shouldResubscribe: true, // is this needed?
},
);
// update subscription on date change
React.useEffect(() => {
// how do I update the subscription here?
// setting containerSubscription.variables = ... does not change the subscription
}, [selectedDate]);
Run Code Online (Sandbox Code Playgroud)
我在阿波罗文档中找不到有关如何解决此问题的任何解决方案。
任何帮助,将不胜感激!