0

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

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.

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...

overexchange
  • 15,768
  • 30
  • 152
  • 347

1 Answers1

1

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://learn.microsoft.com/en-us/azure/jenkins/execute-cli-jenkins-pipeline#add-azure-service-principal-to-jenkins-credential.

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!! :)

KrishnaG
  • 3,340
  • 2
  • 6
  • 16
  • I just realized that you have edited the question by adding Terraform along with Ansible but I think my earlier comment on this still holds good :) – KrishnaG Feb 01 '19 at 16:27
  • [Here](https://blogs.msdn.microsoft.com/brunoterkaly/2015/12/18/understanding-azure-provisioning/) it talks about 5 ways to provision. Why do you prefer third one from this? Which is scripting(azure CLI) – overexchange Feb 01 '19 at 17:39
  • I didn't consider the first way (i.e., Portal) because it's manual way. I prefer the third way (i.e., Scripting) because it's the easiest way in automation options. Next preference would be the fourth way (i.e., REST API). This is next to the third way (i.e., Scripting) because this is having dependency on Curl or Postman. – KrishnaG Feb 02 '19 at 17:14
  • Next preference would be the second way (i.e., ARM). This is next to the fourth way (i.e., REST API) because when compared to other ways this way needs a bit more learning, a little time taking to create, etc. This (ARM) way would be prioritised if the requirement is different from yours i.e., if the requirement is to deploy, manage, monitor many of the resources for a solution as a group rather than handling multiple resources individually. – KrishnaG Feb 02 '19 at 17:15
  • Next preference would be the fifth way (i.e., Management SDK). This is next to the second way (i.e., ARM) because this is having dependency on development languages like .Net, Java, Python, PHP, JavaScript, Go, etc. because Azure provide packages / libraries supporting these management SDK's. AFAIK the management SDKs are ideally for developers who wants to develop cloud-enabled apps with Azure. – KrishnaG Feb 02 '19 at 17:15
  • Just a supplement on this: For **configuration management** on provisioned infra, which tool should I use... Ansible? – overexchange Apr 12 '19 at 14:16
  • IMHO the best one I would suggest to go with is 'Azure management tools for configuration' that are explained here (https://azure.microsoft.com/en-in/product-categories/management-tools/) compared to other market standard configuration management tools like Ansible, Chef, etc. – KrishnaG May 31 '19 at 12:49