使用 Jenkins 进行 Azure 预配 [英] Azure provisioning with Jenkins

查看:15
本文介绍了使用 Jenkins 进行 Azure 预配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 QA 管道(在 Jenkins 中)的一部分,目标是自动配置和配置 VM 以运行 QA 测试.

As part of QA pipeline(in Jenkins), goal is to automate provisioning and configuration of a VM to run the QA tests.

Jenkins 管道可以触发 Terraform 代码以自动配置 VM 和用于配置 VM 的 ansible 代码,但是,回滚错误处理等问题并不容易,除非我们使用一些供应商特定的模板,例如 AzureResourceManager 模板.

Jenkins pipeline can trigger Terraform code to automate provisioning of VM and ansible code for configuration of a VM, but, issues like rollback, error handling is not easy unless we use some vendor specific template like AzureResourceManager template.

那么,对于 Jenkins 管道,在 Azure 云中预配和配置 VM 的最佳方法应该是什么?我们为詹金斯管道编写管道脚本......

So, with Jenkins pipeline,What should be the best approach to provision and configure a VM in Azure cloud? we write pipeline scripts for jenkins pipeline...

推荐答案

由于目标是了解自动配置和配置 VM 以运行 QA 测试的最佳方法,因此我将使用简单的 jenkins 管道脚本来利用其中包含 Azure CLI 命令.准确地说,我只是将 Azure 服务主体添加到 Jenkins 凭据.然后使用 'withCredentials([azureServicePrincipal('SERVICEPRINCIPALCREDENTIALID')])' 编写简单的 Jenkins 管道脚本,然后使用 'sh' 部分让 Azure CLI 命令预配和配置 VM.有关与此相关的说明,您可以参考 https://docs.microsoft.com/en-us/azure/jenkins/execute-cli-jenkins-pipeline#add-azure-service-principal-to-jenkins-credential.

As the goal is to know the best approach to automate provisioning and configuration of a VM to run the QA tests so I would go with simple jenkins pipeline script by leveraging Azure CLI commands in it. To be precise, I would just add an Azure service principal to Jenkins credential. And then write simple Jenkins pipeline script by having 'withCredentials([azureServicePrincipal('SERVICEPRINCIPALCREDENTIALID')])' and then by using 'sh' part to have Azure CLI command to provision and configure VM. For illustration related to this you may refer https://docs.microsoft.com/en-us/azure/jenkins/execute-cli-jenkins-pipeline#add-azure-service-principal-to-jenkins-credential.

关于使用 Jenkins 管道触发 Ansible 代码(使用或不使用 ARM 模板)的方法时回滚和错误处理等问题,该方法可以自动配置和配置 VM 以运行 QA 测试,(您可能已经意识到这一点,但想让您知道)对于某些类型的任务,您可以编写可以利用错误处理功能的自定义模块,并且在少数情况下您可以利用failed_when"选项.您还可以利用块"功能定义一组要在救援:部分中执行的任务.这种阻止"功能特别应该有助于使我们能够回滚事情.

Regarding the issues like rollback and error handling when going with the approach of having Jenkins pipeline that triggers Ansible code (with or without using ARM templates) that can automate provisioning and configuration of a VM to run the QA tests, (you might already be aware of this but wanted to let you know that) for certain types of tasks you may write custom modules that can leverage the error handling functionality and in few scenarios you may leverage 'failed_when' option. Also you may leverage 'blocks' functionality by which you can define a set of tasks to be executed in the rescue: section. This 'blocks' functionality specially should help in enabling us to get the things rolled back.

希望这会有所帮助!!:)

Hope this helps!! :)

这篇关于使用 Jenkins 进行 Azure 预配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆