本文介绍了Azure DevOps 构建中的秘密(dotnet 核心)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有许多测试作为构建的一部分运行.其中一些测试是集成测试,需要一组用户名/密码凭据才能运行测试.

I have a number of tests in my project which are run as part of the build. Some of those tests are integration tests which need a username/password set of credentials in order to run the tests.

我想将这些凭据保留在源代码之外,因此在我的本地计算机上,我将它们设置为用户机密,而在服务器上它们是环境变量.在这种安排下,部署工作得很好.

I want to keep these credentials out of the source code so on my local machine I have set them up as user secrets and on the server they are environment variables. The deployments are working just fine with this arrangement.

我的问题是将测试作为构建的一部分运行.测试未提供任何登录凭据,因此因身份验证问题而失败.如何提供这些值而不将它们添加到 appsettings.json 文件中?

My problem is running the tests as part of the build. The tests are not being fed with any login credentials and therefore are failing with authentication issues. How do I supply these values without adding them to the appsettings.json files?

我正在运行一个 dotnet 核心项目并且有一个标准的 Azure DevOps 构建模板.

I am running a dotnet core project and have a standard Azure DevOps build template.

谢谢!

推荐答案

在构建中声明的非秘密变量在构建代理上自动转换为环境变量.

Non-secret variables declared in the build are automatically turned into environment variables on the build agent.

秘密变量有意变成环境变量,但是您可以添加适合您的平台(Bash、Powershell 等)的命令行或脚本任务,并通过传递您的作为脚本的参数秘密输入.

Secret variables are intentionally not turned into environment variables, but you can add a Command Line or Script task that's appropriate for your platform (Bash, Powershell, whatever) and set an environment variable by passing your secret in as a parameter to the script.

这篇关于Azure DevOps 构建中的秘密(dotnet 核心)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:12