微软刚刚发布了一个新的 Azure Devops. 服务呼吁 Azure PILINES. 这是开源项目的免费。我决定通过移动我的psgraph构建并将管道释放到蔚蓝的管道来检查。

指数

CI / CD管道评论

CI / CD管道对于连续集成/连续交付是短暂的。我有一个较旧的帖子,在那里我分解了我为我的模块使用的CI / CD管道:

要为此帖子添加上下文,该管道是允许我常常允许我作为DEV进行审核。每次办理登机手续都会测试,以便快速了解问题。然后,如果一切都很好,它会自动部署到PSGallery。

build.ps1.

My current pipeline uses AppVeyor to run a build.ps1 script and that script takes care of everything else. The main reason that I use a build.ps1 is that I feel that everyone should be able to build the project locally. This makes it easy to move to a different build system.

My task for today is to get Azure pipelines to run my build.ps1 script.

Azure Devops入门

我开始签名 Azure Devops门户网站.

Azure Devops开始

然后我们创建一个新项目。我给了它名字PSGraph,以匹配该模块的GitHub存储库的名称。

创建一个项目

新建管道

Once the empty project was created, all the screens were filled with big buttons directing me where to go. I basically ended up in the Pipelines -> Build section and created a new build. I selected GitHub and had to authenticate with my GitHub account before I could specify my project and branch.

选择github repo.

建立步骤

我选择了一个空的构建模板,因为我知道我只需要一个版本的一个版本。一旦我进入我的构建定义,我添加了一个步骤来运行PowerShell脚本。我将脚本路径指定为build.ps1。

建立步骤

一旦我走了那一步,我就开始测试我的建造,它主要工作得很好。

Nugetapikey环境变量

One important detail about my previous build was that I had an encrypted value for my NuGetApiKey that was injected by AppVeyor. My build script would read that from $ENV:NuGetApiKey when it would publish the module. So I had to find a way to recreate that in Azure Pipelines.

I started with the Variables tab on the build. I added a new one with the name NuGetApiKey, specified my API key, then clicked the little padlock icon to secure it. If you don’t remember your API Key, then you can generate a new one from the PSGallery website.

构建变量

构建变量 are normally also environment variables. But this is not automatic for the secured variables. So we have to map it into our script. So go back to the tasks and select the PowerShell build step that we added previously. Expand the Environment variables and add our API Key. I used the same name so it is called NuGetApiKey with a value of $(NuGetApiKey).

脚本变量

该值的语法对于Azure管道特别特殊。这就是您在构建步骤的属性中引用构建变量的方式。有一个大量的名单 预定义的变量 您也可以使用的可用。

启用连续集成

我们需要做的最后一件事就是在我们的构建中持续集成。转到“触发”选项卡,持续集成是第一个可用选项之一。这是让您在每次合并到Master时都会创建运行的步骤。

脚本变量

If you also want your build to run for pull request validation then you can do that on this screen too. My build.ps1 has logic built into it to detect if its on the master branch or part of a pull request so it is safe to run in both scenarios. An alternate way to do this would be to set up a 2nd build for pull requests that does not execute the publish.

运行构建

现在一切都到位了。我们可以恢复我们正常的工作流程,可以创建提取请求,以便更改,以查看构建验证的更改。然后,一旦它们被合并到Master中,主要构建将运行并发布模块。

结束思想

我已经使用了一段时间的TFS一段时间,而且大多数这些屏幕和选项都是一样的。我用手做了一切,只是为了看到所有的碎片到位,但这个设置可以自动化,并且支持基于yaml的Configs。我计划在找到时间探索这些其他功能。

我希望这能为您提供快速跳跃,了解如何为您的一些项目利用Azure Devops管道。