How integrate pull request Azure Devops Repository With Jenkins - jenkins

I have a Git repository on the Azure Dev-ops server and use Jenkins for continuous integration build.
I want to know that how a specific branch like master Jenkins can automatically run the build and then notify the user via a shell log that the build was successful or not?

Microsoft seems to have the thing pretty well documented, Create a service hook for Azure DevOps Services and TFS with Jenkins
Set up the Jenkins job, set up the TFS / Azure DrevOps ServiceHook, off to the races.
We have it working fine for Jenkins 2.x and AzureDevOps on-prem. Best to use service accounts with limited necessary permissions on both sides.

Related

bitbucket and TFS - any 3rd party opensource tools to connect or integrate between these 2 repositories

Currently my On-premise company is using Team Foundation Server (TFS), it is doing multiple things like work tracking and build.
We brought Bitbucket to separate code repository, we still want to continue using TFS for work tracking. We are looking for any (opensource project examples) connectors or integrators or plugins somewhat similar to connect between Bitbucket & TFS . If there is any opensource project examples to connect these somewhat similar will try to tweak it.
Azure Pipelines, Azure DevOps Server, and TFS integrate with a number of version control systems. When you use any of these version control systems, you can configure a pipeline to build, test, and deploy your application. Please check Supported source repositories of Azure DevOps Server/TFS.
Bitbucket Cloud repository type is supported in Azure Pipelines, but not in on-premise Azure DevOps Server/TFS. As a workaround, you can use the Other Git or External Git repository type in on-premise Azure DevOps Server/TFS, to build repositories in Bitbucket.

Publish Jenkins build output to Azure Dev Ops for release pipeline

I am looking for how to publish a Jenkins build output to Azure Dev Ops for the purpose of deployment.
All of our code is on TFS 2015 and the build definitions are in Jenkins.
We will be migrating to Azure Dev ops completely, but for now I just want to manage the deployment through Dev Ops. I will script the agent on each of the hosts and move the files to their correct locations.
Looking at the Azure Cli - there Publish Pipeline Artifacts
I can't use a service connection to Jenkins because the server is behind a firewall. I need to be able to publish from Jenkins to Azure Dev Ops.
Any creative ways to do this?
for example, you could create a nuget package (or any other package) from jenkins build and push it to the artifacts feed you create in azure devops. Next is to create a release pipeline with a trigger for Azure Artifacts (with enabled continuous integration trigger) for the latest package version.
here is an example on how to publish nuget packages from jenkins.
EDIT
be aware of the size limitations of Azure Artifacts. As per today, only 2 GB are free of charge.

Service hook in azure devops not triggering a build in jenkins job

I am trying to use azure devops service hook for Jenkins build. While testing from azure devops to jenkins test connection is successful but GitHub hook trigger for GITScm polling is not triggering the build if I am committing a code change in azure devops repo.
If you just want GitHub hook trigger for GITScm polling, you can check in there for help.
If you have trouble triggering a build in jenkins job when change code in Azure DevOps, here are two possibilities.
On the one hand, the url that you set was not right format. Please check your URL for your Git repository in Azure DevOps Services. The URL is in the form :
https://dev.azure.com/{orgName}/DefaultCollection/_git/{projectName}.
On the other hand, you choosed other event from Azure DevOps Services that you want to trigger a Jenkins build. Please choose as follows:
For more details,please check in this link.

Configure Jenkins CI build to use TFVC hosted in Azure DevOps

We recently migrated from an on-premise TFS server to Azure DevOps. Our team uses TFVC for source control, and I'm getting the following exception when Jenkins polls for new check-ins:
FATAL: This server requires federated authentication but no mechanism was available to handle it.
com.microsoft.tfs.core.exceptions.TFSFederatedAuthException: This server requires federated authentication but no mechanism was available to handle it.
Given the exception class name is TFSFederatedAuthException I suspect Azure is expecting some sort of OAuth integration, but Jenkins doesn't appear to support that for TFVC.
All I did was change the Collection URL for that Jenkins build to https://dev.azure.com/MyCompany. The Project path remains the same, and I verified this, because I was able to re-map all of my TFVC branches in Visual Studio by just pointing to the different collection URL and keeping the same project path. A screenshot of the Jenkins source control config is below:
This Jenkins server is internal with no public facing IP address or host name.
How can I allow Jenkins to poll a TFVC repository hosted in Azure DevOps in order to trigger a CI build in Jenkins?
Why not use Azure pipelines? That's a much bigger migration effort at the moment, and I'm just trying to solve a short term problem.
Using Azure pipelines is my long term goal, but I need to figure out how our automated tests can use an Oracle database first, because all data is deleted before each test is executed using Selenium.
Azure DevOps uses OAuth to communicate by default, putting in your username and password won't work because of that. Instead, the trick is to generate a Personal Access Token (I suspect the Code|Read+Write scope should do it) and pass that in.
For the username pass in ., for the password your generated personal access token. Give the token a nice name so you know which one is about to expire once you get the email notification.

Publish latest build artifact from "LOCAL" Jenkins to Azure DevOps Release Pipeline?

I have a local Jenkins server running on one of my spare computers (win10). Note that it is not behind any sort of a server and hence is only available within my local network. I have set it up so that it does the continuous fetch from my remote git repo and builds the artifacts and archives them for a successful build. I would like to publish these archives to my AzureDevops Release pipeline. How do I do this? (And yes I have looked through all the tutorials but they assume that I have Jenkins running on a VM somewhere on the cloud).
So far I have had no luck with the tutorials on the web since I donot really have a URL to this instance of Jenkins since it is only available on my local network. I cannot really build these artifacts on a remote Jenkins server, so I am really restricted to using this solution for running the builds.
I am looking to have these archives that Jenkins builds be directly available within my Azure DevOps release pipeline, on every successful build. Thanks for the help!
So since nobody else has answered this I am going to detail what I ended up doing (maybe not the best of the approaches but it works for my setup, suggestions are welcome!).
To interface with the Azure DevOps platform from a local machine you will need to configure a self-hosted agent (based on your specific OS), which will allow you to trigger builds, archive and upload the build artifacts to the Azure DevOps platform. This way you also donot have to poll for SCM changes too (which I think is not that elegant sometimes).
1. So you will need to go through the setup as outlined here for you local self-hosted agent:
Windows: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
Linux: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-linux?view=azure-devops
MacOS: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-osx?view=azure-devops
NOTE: I have chosen to run the agent as service on windows for my setup
2. Next setup your Jenkins build job how you normally would, with your usual repo access setup. Things to keep in mind are following:
Under "Build Triggers", select the Poll SCM option, but make sure that the schedule is blank, this will make sure that the trigger from your post-commit hook from the agent works. Example setup shown below:
Under "Post-build Actions", make sure that you are archiving the artifacts as required. Example shown below:
3. Now time to setup your project's "Jenkins Service Connection", this can be accessed from the Project Settings tab on the bottom left of you project view in Azure DevOps. Note that this basically helps you self-hosted agent to locate and communicate with the Jenkins instance running locally (or an other network accessible location!). Go under Pipelines -> Service Connections and a new service connection for Jenkins. Note that the trick here is to use the URL for the connection as seen by you local self-hosted agent, which means it can be just any IP (including localhost) that the agent can access normally. Username and password are the same as the ones you setup in Jenkins. Example shown below:
NOTE: You can try to do "Verify and Save" but it will throw an error, so ignore the error or just go ahead and "Save without verification". Also you will have to do this per project, unlike the self-hosted agent setup which is per machine.
4. Now you just need to configure your build pipeline to give jobs to the right agent and pointing to the right service end-point. Now under you build pipeline settings use the agent pool that has the self-hosted agent(s) which can access your build servers. And choose the Jenkins connection that you just created in the above step. The rest of the setup is identical to how you would normally setup your project's build pipeline. An example would be as follows:
NOTE: The key here is the correct "Job name" (this should be the same as the one you have setup in you Jenkins build server instance) and the correct "Jenkins service connection".
5. The rest is straight forward in the sense that you just now need to make sure that you have a step to "Download artifacts" (NOT necessary if you donot want the artifacts on the DevOps platform) & "Publish Artifacts" (this is needed for your release pipeline to see that build artifact and to trigger it too if you want), after your jenkins queue job step. Make sure to setup the correct job directories for download from you local self-hosted agent. Example setup for both the steps:
NOTE: If you are having trouble with the paths for download and publish refer to this link for predefined variables for the self-hosted agents: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
6. Now in your release pipeline you should be able to add the artifact sources from you build pipeline. Example shown below:
Now you should be able to get the local artifacts in the cloud on the Azure DevOps platform, in case you cannot use the build agents provided by Microsoft for any reason!

Resources