Jenkins Pipeline with build stage - jenkins

I have a pipeline with four stages namely build, deploy, test, release and i am about to run two concurrent builds and i give manual approval to all by giving input to all stages, Suppose if i am holding my approval in deploy stage (3rd stage) in first build , the 2nd build should wait in test stage (2nd stage) before i give approval to previous deploy stage(3rd stage) in 1st build, (i.e) 2nd build should not pass the stage of previous build? . How to do this?
i tried but didnt get idea

Related

Agent field not being populated in Jenkins Pipeline jobs

Trying to investigate Jenkins build time by node I noticed that when we switched to using jenkins-timeline our jobs stopped filling in the "Agent" field on the "Build Time Trend" page.
Old pre-pipeline jobs show the agent name in that list, but new pipeline jobs just show a blank agent field.
If I go into an individual pipeline build, I can look in the Console Output and find the Running on line to work out which agent was used, just as I can see the Building remotely on line in the console output of non pipeline builds.
Is there a way to get pipeline builds to fill in the Agent field with the machine the job was actually run on?
I believe Jenkins does not collect this information when running Pipeline jobs, as Pipeline job may run on many agents in parallel.
We wanted to have that information so we run an instance of InfluxDB and send metrics there. These metrics include the agent name, so this is available for analysis later.

Queuing the entire Jenkins pipeline

I have three jobs in my jenkins pipeline. The requirement is to queue the pipeline, ie, it should run as it is for the first build; for the second build (before the first gets completed), the flow should be - get all the 3 jobs done from the first build, then go for the second build.
PS: Is it possible through Build Blocker plugin? If so, how?

How to make production deployment a part of CI/CD pipeline

I want to build a new pipeline for my project which includes production deployment as a stage. A sample can be seen in the below picture.
Once the pipeline has passed all the quality gates, it will be deployed to dev environment automatically, and functional test will run in the next stage. There is a manual approval required at this stage, once approved the next step will be deploy to prod/preprod. I am able to achieve the goal till this point. I am stuck at following step:
Can we keep this build forever, or for a specified duration, say, 1 or 2 months, and continue from the same stage when required? For example, the git master branch is getting updated very frequently, and the builds are getting triggered automatically, all builds should reach this stage and wait. Only the build having approval should be able to proceed forward.
There can be one other way; I can have a separate job for deploy to preprod/prod. But, I want to know if this is possible.
Regarding - Can we keep this build forever, or for a specified duration, say, 1 or 2 months...
You could achive it partially - build could stop at manual step for a period of time. But remember - while job is running it is using executor from agent. Once you use all executors you can't start another build.
... and continue from the same stage when required? - It's not possible.

stage approval through API

I need to promote to next stage in multiple builds (which are on progress) through approvals.
Is it possible to give pipeline stage approval through API in Jenkins using build numbers?

How to prevent older builds from entering stage with concurrency 1

We've setup a Jenkins build pipeline that uses Maven to build a large project, including stages for update, compile, unit test and deploy (to Nexus). The "deploy to Nexus" stage has concurrency 1 to ensure that no more than one build is in this stage at any point in time. However, this setting does not prevent older builds from entering that stage after a later build has finished it.
For instance, if build #2 is startet after build #1 and hits a fast node, it may outrun build #1 and enter the "deploy to Nexus" stage first. Build #1 cannot enter this stage at the same time, so it waits until build #2 is finished; but then build #1 enters this stage and thus overrides the Maven artifacts deployed by the later build, which is not what you want.
There must be a way to avoid this, i.e. to prevent older builds from entering a stage that was already executed successfully by later builds. I just could not find a solution for this problem... Any thoughts?
The upcoming milestone step is supposed to solve this.
Send the current build number of the job and add a simple condition to test it with the latest successful build number of the job using the following Jenkins URL:
http://JenkinsMaster:Port/job/MyJob/lastSuccessfulBuild/buildNumber
If the current build number is smaller than the last successful one then skip the upload.
Good Luck!

Resources