Best approach for build/release pipeline in AzDo for 2 separate projects/repos - docker

I have 2 separate projects in AzDo, project-1 contains repo to build docker image and tag it accordingly like 1.0.0 , 1.0.1 etc. and in another projects-2 there are 2 separate repos which uses these tags. currently this is manual in repos#project-2.
My question is how can I automate the process in AzDo, that means if there is a new tag for docker in repo#project1 then it will automatically build the repos in project-2 with this new docker tag.
e.g. currently project-1 has image:1.0.0 and this is used in 2 repos in project-2 manually referring to 1.0.0.
Now I build a fresh tag in project-1 with tag 2.0.0, so how can I automatically build 2 repos#project-2 with this new 2.0.0 . Is there any link/signal from one build/release pipeline to another pipeline/project?
Any advice is greatly appreciated.

The easiest way it will be to use pipeline triggers which allow you to trigger one pipeline after another. You may have an issue fetching docket image tag but simply you may resolve this by hitting your container registry.
Please check out also stages filter, maybe they will provide a value for your case.
In this sprint, we added support for 'stages' as a filter for pipeline resources in YAML. With this filter, you don't need to wait for the entire CI pipeline to be completed to trigger your CD pipeline. You can now choose to trigger your CD pipeline upon completion of a specific stage in your CI pipeline.
Another option will be to use webhook when your image is pushed to container registry and trigger another pipeline over REST API.

According to your description, seems you are talking about two different team project.
Is there any link/signal from one build/release pipeline to another pipeline/project?
You want to trigger a pipeline in another team project.
In the classic editor, pipeline triggers are called build completion triggers. You can select any other build in the same project to be the triggering pipeline.
Thus you have to specify pipeline triggers directly within the YAML file instead of configuring build completion triggers in the UI.
# this is being defined in app-ci pipeline
resources:
pipelines:
- pipeline: securitylib # Name of the pipeline resource
source: security-lib-ci # Name of the pipeline referenced by the pipeline resource
trigger:
branches:
- releases/*
- master
To trigger a pipeline upon the completion of another, specify the triggering pipeline as a pipeline resource.
Note: If the triggering pipeline is in another Azure DevOps project, you must specify the project name using project: OtherProjectName.
More detail sample and limitation refer: https://stackoverflow.com/a/61398607/5391065
For Classic editor, you need to use some 3rd-paty extension such as this one--Trigger Azure DevOps Pipeline, it's able to select other project where the pipeline resides.

Related

Jenkins pipeline for multiple repo

I am working on micro-service base Jenkins pipeline. There is similar code pattern / structure in Bitbucket repository for Java and angular based code. Can I manage multiple repositories with single pipeline with dynamic approach which can provide filter option (like AJAX in java) in drop down like I can get more than one repositories in drop down option and I can select any repository, based on this repository, I can get branches from this repository in next drop down and I can execute Jenkins pipeline.
Do we have any Jenkins plugin which can provides filter option for Bitbucket repositories in Jenkins.
Presently I am using Git parameter option in Jenkins pipeline (Build with parameter) and then created several pipelines.
Are you saying that you want a job in which you can select a repository and then select a branch from that repository and hit GO and build that branch of that repo? If this is the case then the answer is no.
You would have one Job per repository, and if that job is a multibranch pipeline then you would be able to select the branch to build from there.
You can enable all the repos and branches to use the "same" pipeline that you then submit parameters to using a Shared Library

Jenkins Build Multiple projects in same repository

Previously we had a single monolith in GitLab repository and we used to build project in Jenkins using Jenkinsfile.
Now we are migrating it into multiple microservices and all reside in same GitLab repository. Is it possible to create pipelines for this type of setup or do we need to have each microservice in separate repository. If it is possible please point me to appropriate resources.
Each microservice can have its own Jenkinsfile, you have to tell to the Jenkins job the path of the Jenkinsfile if it is not located at the root path.
In your pipeline configuration job choose "Pipeline script from SCM" and set the "Script Path".
To only checkout the microservice you need, you can use in the "SCM" then "Additional Behaviours" the "Check out to a sub-directory" (then if the Jenkinsfile is now at the pseudo root path, you won't need to change the default "Script Path").
Yes it is possible to create pipelines to build/test/deploy from a single repository.
Use Declarative Pipeline in Jenkins.
You can have your microservices separated in different directories in a single repo and can build them all using a single pipeline using the stages & dir() option in Jenkinsfile. We're building close to 15 components from a single pipeline and push it to it's relevant artifactory from the same job. You can build non-dependent microservice components parallely too.
Documentation --> Jenkins Pipeline,Jenkinsfile

Pipeline to use artifacts from 2 projects associated by the same git branch name

the company where I work for is evaluating jenkins 2.71, in particular the pipeline and blue ocean plugins. We already tested also GoCD and we need, as in GoCD, a way for a pipeline to automatically fetch the artifacts from 2 other pipelines (taking the last successful result of each one of them), here our case.
We have these initial pipelines (build & run tests), which reflect 2 projects:
frontend, ~ 15 minutes
backend, ~10 minutes
I created a pipeline called configure (~1 minute), with e.g. a parameter called customer-name, which takes backend and frontend files and puts them together, then applies specific customer specific configurations and customizations and produces deployable artifacts. Instead of "customer-name" I could also parallelize this job to create all the artifacts for each customer at once, separated in different directories.
The next pipeline would be to deploy them on different test servers separated for each customer. This could be also part of the same configure pipeline, we still have to see how to put things together in jenkins...
Ideally, I need configure pipeline to be triggered automatically (or also on demand) after each frontend or backend success and take as input the last successful artifacts from these 2 pipelines, but not just having the last successful build, we need as dependency the git branch name.
E.g. we have:
backend branches:
master
release/2017.2
frontend braches:
master
release/2017.2
In the pipeline editor, I found a Build Triggers option and set it as follows: Build after other projects are built > Projects to watch: frontend, backend > Check Trigger only if build is stable or better in my test environment full of failures Trigger even if the build is unstable.
Searching further, I found Copy Artifact Plugin
But now the big question, how to fetch the last successful artifacts from these pipelines with the same git branch name?
Because we don't want to mix e.g. a backend build of "release/2017.2" with frontend "master", it has to find as the last successful build having the same relationship or parameter or whatever you wanna call it, in our case the association is the git branch name.
Is it possible to achieve this? If yes, how?
The copy artifact plugin seems to work in a freestyle project. Would it work in a pipeline? That's also a concern...
Thanks
Yes, the Copy Artifact plugin does work in both freestyle and pipeline projects; pipeline uses the copyArtifact function that I referenced in my comment. Note that if you go to the Pipeline Syntax link, it's kind of hidden: you have to first select "step: General Build Step" from the drop-down, then it will give you the Copy Artifact pipeline command builder.
I'm going to assume that your frontend and backend projects are built as multi-branch pipelines, as that would probably be easiest to maintain so that you don't have to keep creating new projects for every release. You can reference these projects from other projects by referencing <project name>/<branch name> (sometimes I've had to replace the / with %2f instead, I think mostly on freestyle projects). You could then set up your configure project as a parameterized build (either pipeline or freestyle), say with a string parameter of PROJECT_BRANCH_NAME. Then put in the following in your frontend/backend project pipeline scripts to trigger a build of your configure project
build job: 'configure', parameters: [[$class: 'StringParameterValue', name: 'PROJECT_BRANCH_NAME', value: ${env.BRANCH_NAME}]]
Then you should just be able to make your configure project reference the frontend/%PROJECT_BRANCH_NAME% and backend/%PROJECT_BRANCH_NAME% (or ${env.PROJECT_BRANCH_NAME} in a pipeline script) when copying the artifacts.
Also, is there a particular reason why you're evaluating specifically Jenkins 2.7? 2.7 is a year old now, and there have been a few new LTS releases since then. I'd recommend staying reasonably up-to-date unless you know there's a specific reason you want 2.7.

How can Jenkins read a polling text file checked in GIT to trigger a deployment?

Current scenario: Build and deployment happens in development environment and the code is checked in to GIT and the JAR file is placed in Nexus. Then a change request is raised to deploy the same to the QA environments. The CR is attached with two parameterized text files (One of which contains the nexus path and other contains website URL) which act as input for parametrized build along with selection of environment. Run deploy
Target Scenario:We want to remove the CR part and in doing so we want a file (containing parameters which were attached in CR) which when pushed to GIT, a copy-paste should happen to the parametrized Jenkins job in respective parameters and select the environment from dropdown.
What is the best way to achieve this, either by creating another Jenkins job which can read the parameters from the file or is there any other way.
P.S. We don't want to make any editing in the existing Parameterized Jenkins jobs.
Using the Jenkins GitHub Plugin, you can create a separate job with a GitHub build trigger. By adding the GitHub repo (where the parameter file is pushed) to this Jenkins job, you can process the file to get the parameters you want in order to kick off the appropriate Jenkins jobs.
For Jenkins to process the parameters, one option is to use the EnvInject Plugin. (As suggested in this answer.) Another suggestion: Extended Choice Parameter Plugin (from this answer).

How to get URL of pipeline job in jenkins

We are setting up a continuous delivery pipeline in Jenkins, using the build pipeline plugin.
Our deployment steps uses a proprietary deploy tool (triggered by a HTTP request from jenkins), but we need to have an additional Jenkins step for acceptance tests on the then deployed project. So our deploy tool will need to trigger the last pipeline step.
The jenkins setup for this is obvious:
For a Manually Triggered downstream build step: To add a build step
that will wait for a manual trigger:
Select the Build Pipeline Plugin, Manually Execute Downstream Project check-box
Enter the name(s) of the downstream projects in the Downstream
Project Names field. (n.b. Multiple projects can be specified by using comma, like "abc, def".)
Source: Build Pipeline Plugin
The problem is: I can't seem to find a way to trigger this downstream build through a URL.
In fact I'd need the URL in the deploy job, so I can send it to the deploy tool as a callback URL. Can anybody help?
If I understand correctly, you want to use remote access API, which to my knowledge is no different between general project or pipeline one.
Take a look here:
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
Submitting jobs
Jobs without parameters
You merely need to perform an HTTP POST on JENKINS_URL/job/JOBNAME/build?token=TOKEN where TOKEN is set up in the job configuration.
As stated above by #rafal S do
read a file which has list projects name for which build job has to be triggered do a curl HTTP POST on JENKINS_URL/job/${JOBNAME from the file}/build?token=TOKEN within a for loop , where for loop has list of all project names from the file you read

Resources