简体   繁体   English

将环境变量值注入 GitLab CI/CD 管道中的配置文件

[英]Inject environment variable values into config files in GitLab CI/CD pipeline

When I previously used Azure DevOps for CI/CD, we would store secrets like database passwords in Azure DevOps environment variables, and then during the CD phase the appropriate environment's passwords would be injected into the connection strings in config files.当我之前使用 Azure DevOps 进行 CI/CD 时,我们会将数据库密码等机密存储在 Azure DevOps 环境变量中,然后在 CD 阶段将适当环境的密码注入到配置文件中的连接字符串中。 This meant that the passwords were never stored in the repo itself.这意味着密码从未存储在回购协议本身中。

I'm now trying to configure CI/CD in our self-hosted GitLab instance and have it working at a very basic level but I'm wondering how I go about doing the same thing as I did with Azure DevOps.我现在正尝试在我们的自托管 GitLab 实例中配置 CI/CD 并让它在非常基本的级别上工作,但我想知道我 go 如何做与我对 Azure DevOps 所做的相同的事情。 I have created environments for my project and variables (masked and protected) for each environment.我为我的项目创建了环境,并为每个环境创建了变量(屏蔽和保护)。 But is there a way to inject the values of the variables into config files during a CD deployment job?但是有没有办法在 CD 部署作业期间将变量的值注入配置文件?

I think for the Azure DevOps pipeline we executed a PowerShell script to replace some placeholder text in the config files with the values of the variables at deploy time.我认为对于 Azure DevOps 管道,我们执行了一个 PowerShell 脚本,以在部署时用变量值替换配置文件中的一些占位符文本。 Might a similar approach work with GitLab's CD pipelines?类似的方法是否适用于 GitLab 的 CD 管道? GitLab's documentation on where variables can be used doesn't seem to mention anything like this. GitLab 关于在哪里可以使用变量的文档似乎没有提到这样的事情。

You can store it in your project’s Settings > CI/CD and expand the Variables section您可以将其存储在项目的设置 > CI/CD 中并展开变量部分
You can also store in Group variables if your using a private instance of gitlab如果您使用 gitlab 的私有实例,您也可以存储在组变量中

https://docs.gitlab.com/ee/ci/variables/index.html#add-a-cicd-variable-to-a-project https://docs.gitlab.com/ee/ci/variables/index.html#add-a-cicd-variable-to-a-project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM