Provisioning an Azure VM agent using a Jenkins Multipipeline - azure

I have a Jenkins instance running on an AWS EC2. Rather than use the built-in nodes(i have disabled them), I need to provision an Azure VM agent, perform builds and execute tests on that agent. Using the https://plugins.jenkins.io/azure-vm-agents/ via a freestyle job I was able to successfully provision an Azure VM agent on demand. However I an unable to achieve the same via a Multibranch pipeline ( there is a seperate repo for Jenkins File and one for the code repo) (plugin https://plugins.jenkins.io/remote-file/). It does not seem to kick of the Azure VM agent and fails waiting for an agent. If i enable the built-in node, it works. So it appears that via the pipeline the azure-vm-agents is not triggering for provisioning. . There appears as if a link For how to select agent in pipeline, refer to this doc. within the https://plugins.jenkins.io/azure-vm-agents/ page does not lead anywhere. Any thoughts much appreciated.

Related

Execute script on Azure Windows VM via Azure pipeline

I am using third party software for master data management. This software does not have API's to perform deployment across environment. It has command line utility which needs to be installed on machine and call the commands to perform the installation. I am looking to automate this solution using Azure Devops pipeline. What I am trying to do is as below
Create windows VM in Azure and install command line utility on it.
Store script in some folder in the VM.
Use Azure pipeline to call this script which is stored in my VM.
I don't even know if it possible to do such things. I tried looking on internet on how to call script stored in VM via Azure pipeline but didn't find any useful link.
If any one has done such activity or have an idea how can it be achieved please help.
this can help you
Running the command line in a Azure Virtual Machine is fully supported in Azure Pipelines. You could install a self-hosted agent in the VM.
Before that, I recommend that you could create a new agent pool for the self-hosted agents. Please go to the organization settings -> Agent pools-> click the "Add pool" -> choose the "self-hosted" type.
Then, you could refer to this document to complete the installation. When you configure the agent, you could choose the new created agent pool.
After installation, you could create a pipeline, choose the new created agent pool and add a Command Line task to run the command line. Of course, if you have many agents in the same agent pool, you could also set the demands in the pipeline to specify one agent.
reference : Is it possible to run a command line in a Azure Virtual Machine from Azure DevOps pipeline?

Assigning a vm for azure pipline task rather than creating a new vm's for each run

As a beginner of DevOps, I would like to know how to use one VM for azure pipeline runs. When starting the run of the azure pipeline task it always gives a fresh VM from azure.
For caching and file saving purposes, I want to use a reserved VM for pipeline run.
Appreciate your suggestions and support.
Check the pic, In the Azure DevOps, we could run the pipeline via Hosted agent and Self-Host agent.
Azure Pipelines provides a pre-defined agent pool named Azure Pipelines, this is hosted agent and each time you run a pipeline, you get a fresh virtual machine. The virtual machine is discarded after one use.
For caching and file saving purposes, I want to use a reserved VM for pipeline run.
We could refer to this doc to install the self-hosted agent, it will save the cache.
You can setup a 'self hosted agent'. That would be your own VM, which you have total control over. I'm not sure whether this will be any cheaper than hosted agents.
I've used a self-hosted agent a while ago, and saved some money booting the VM only when needed. After a while it would shutdown again.
Source: Self-hosted agents

Integrating Local Jenkins Setup with Azure Dev OPS

I wanted to know if there is any good documentation available for the below scenario
I have a jenkins master running on my laptop
This jenkins master have several jobs which executes locally
I now want to call these jobs from Azure Dev Ops. Meaning a Devops job from Azure cloud should trigger a build on my local Jenkins setup
I saw several videos but I am finding it difficult to get around it.
Is there any easier way by just making use of a plugin to connect and executing the job?
I did saw some Udemy videos but then those involve a lot of setting to be done and does expose your system to outside vulnarabilities as firewalls and router settings are played on with.
Any help would be appreciated. Thanks!
You can enable Trigger builds remotely for your jenkins jobs, and then use a script task in the azure devops pipeline to trigger your jenkins pipeline. See below steps:
1, Firstly you need to create a self-hosted agent on your local jenkins server machine. Since the jenkins server is running locally, you need a local agent to communicate with your local jenkins server. Follow the steps here to create your local hosted agent.
2, Enable Trigger builds remotely on Jenkins
Go the the Build Triggers Tab of your jenkins pipeline configure page--> Then check Trigger builds remotely--> Specify a Token (will be used in the URL)
3, Define a secret variable to host your jenkins password in azure devops pipeline:
4, Add a bash task in your azure devops pipeline to run the below curl command:
#token must be the same with the token you entered in above step
curl -u $(username):$(password) http://localhost:8080/job/myproject/build?token=anytoken
See this thread trigger jenkins job via curl command remotely for more information.
5, Targeting your self-hosted agent pool to run your azure devops pipeline on self-hosted agent.
Then your local jenkin jobs will be triggered by the azure devops jobs.
Update:
You can also use Jenkins queue job task to queue a jenkin job in azure devops pipeline. See below steps:
1, Create a API Token in your Jenkin server.
Go your jenkin account configure page. To create a API token.
2, Add Jenkins queue job task in azure devops pipeline.
3, Click the Manage link to create a jenkins service connection--> In the newly opened page-->Create Service connection-->Select Jenkins--> Next
Enter the required information as below screenshot. Note: username is your user account for jenkin server, the Password is the API Token You generated in above step.
4, Configure your Jenkin queue job task as below

create azure devops windows self hosted agent remotely

Need to create azure devops windows self-hosted agents programmatically (Need to install Remotely for the existing VM).
I have PS script and it is working well if i run it (as admin) inside the virtual machine and agent is getting installed successfully. But i want to create this agent for the existing VM without logging in (Remotely i need to install the agent), because i will need to just add the ARM template in Azure devops pipeline and that should create the Agent for the existing VM.
As this needs to be installed remotely and securely, i shouldn't use custom script due to some restrictions.. It would be really great if we can achieve this installation remotely without custom script and using any other automated way.
Any information will be helpful, thanks.
I have found out a way using Run-Command. This is another helpful option to run the PS scripts remotely on a Virtual machine. In addition, this executes the script with elevated permissions which is really helpful in many scenarios.
Source: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command#powershell
This can be performed using via Portal, Powershell and CLI as well.

Azure DevOps Release Pipeline: How to copy to my VM

I created a simple .net core console app. This app's repository is a Azure DevOps one. I have also created a ubuntu vm which i can successfully connect to, to receive the deploy.
I have managed to deploy my app from my local computer, by cloning, building and pushing it (via scp command).
Now I would like to do this using azure devops pipeline?
I managed to build the app, but now i can't seem to find help regarding how to execute the scp (or a alternative) command...
Edit1:
Ok, this is turning out to be an order of magnitude harder than I expected. I'm giving up for now. I've been trying to figure this out for almost 2 work-days. I can't believe that a task that requires 4-6 commands on a script on my local machine should require this much effort to do on a devops environment...
You can configure a deploy agent to your VM and use a release management to copy and configure your applications:
Deploy an agent on Linux
Define your multi-stage continuous deployment (CD) pipeline
Have a look at the Copy files over SSH pipeline task which supports SCP.

Resources