Azure devops pipeline triggers - tfs

I am trying to build a pipeline that gets triggered by other pipeline and should not be able to be queued by itself. I am unable to find a way to do the same. Any help would be greatly appreciated.
Updated:
Structure i am looking for is PipelineA triggers PipelineB and waits for PipelineB's completion. If i add a trigger saying start when completed it wont trigger PipelineB since A is technically not complete.
Thanks

Assuming you are using Azure DevOps, you can add a pipeline trigger to run your pipeline upon the successful completion of the triggering pipeline.
To prevent triggering two runs of a pipeline, you must remove its own CI trigger or pipeline trigger.

We do not have this build-in feature at present. You need to customize yourself.
Triggering a pipeline can be done via the API and trough PowerShell. You can write your own script file and use the PowerShell tasks.
Then you could use Rest API to query to build result for you have triggered above.
Finally use a task Conditions.
Inside the Control Options of each task, and in the Additional options
for a job in a release pipeline, you can specify the conditions under
which the task or job will run.
Unless the query result of you trigger build PipelineB is completed/succeed. Then you could continue to run left tasks in Pipeline A

Related

How to define trigger source in jenkinsfile

My Jenkinsfile is built from several stages and can be triggered by the scheduler or via push to Gitlab. I would like to use the trigger source in order to skip several stages for a trigger. How can I identify which event triggered the job?
If you mean Push/Merge events, you can check env.gitlabActionType variable.

Is there any way to link two different pipelines using jenkinsfile?

Developer team needs a pipeline should only be allowed to start only if another related pipeline has completed and they need the pipeline view on same page
It is something like this , a set of stages complete and the next stages would start when project manager starts the pipeline manually .
Simply they need to visualize both pipelines in a single page like below picture.
(https://puppet.com/sites/default/files/2016-09/puppet_continuous_diagram.gif)
You can use the step build job: '<first_pipeline>', parameters: [...] in say, stage 1 of your second pipeline as a upstream job. Then define the steps of your second pipeline from stage 2 onwards. This will make sure that the first pipeline is always built when you trigger the second and also works with delivery pipeline view for single page visualization.
Or, if you just want to check if the first pipeline is completed without actually triggering it, use the api <jenkins_url>/job/<first_pipeline>/lastBuild/api/json in stage 1 of your second pipeline with a while loop to wait until the status is “completed”.
I haven't heard of a way to link them, but you could write the steps in the same pipeline.
You can work with input steps to ask for the project manager to confirm. Note that this halts an entire build processor until confirmed (or you set a timeout).
You might also want to have a look at conditional steps.

Updating declarative pipeline job's cron triggers doesn't update triggers

I have a declarative pipeline job defined as a pipeline script (not pipeline from SCM). It has a cron trigger:
triggers {
cron('H */4 * * 1-5')
}
I've run this a few times on-demand and cron triggered, and everything is fine so far. Now if I change the cron trigger, jenkins does not pick up the change, the old trigger is still in effect until I force a job run.
How do I get Jenkins to use the changed triggers without running the job manually? I think the question can be extended to any declarative job definition changes really, how do I get jenkins to update job settings without being forced to run the job.
This is related to how Jenkins pipeline works. Triggering as well as other job configurations are only loaded into Jenkins itself only after the job is executed once. It is simply the egg and the chicken question.
Since a pipeline job should be in the context of the place that stored it (Github, for example), you should consider triggering it from there then use some internal logic to decide if to run it or not.
The complexity of this solution should be relative to the number of times you update your trigger.
In short, currently, at time of writing, you can't.
I work around this for parameterised pipelines by adding a "noop" option and them making sure my pipeline does nothing when this option is selected. That way the job runs but has no side effects.
If your pipeline is not parameterised we are currently, as I said, out of luck.

Jenkins job wait for first successful build of other job

I have a Jenkins job that should not start building until another job has been built successfully at least once. They are not related per se, so I don't want to use triggers. Is there a way to do this?
Some background: I'm using SCM polling to trigger the second job. I've looked at the Files Found Trigger plugin, but that would keep on triggering the second job after the first on has been built. I've also found the Run Condition Plugin, but that seems to work only on build steps, not on the entire build.
Update - The second job copies artifacts from the first job. As long as the first job has never completed successfully, the Copy Artifact step fails. I am trying to prevent that failure, by not even attempting to build the second job until the first job has completed once.
One solution is to use the Build Flow plugin.
You can create a new flow job and use this DSL:
I've used 10 in the retry section but you can use any numbers.
This flow job can be triggered by monitoring the same SCM URL of your second job.
Update, here is a second solution.
You can use the HTTP Request plugin.
If you want to test that your first job has been built successfully at least once, you can test this URL:
http://your.jenkins.instance/job/your.job/lastSuccessfulBuild/
One example:
As my build has never been successful, the lastSuccessfulBuild URL doesn't exist. The HTTP Request changes my build status to failure.
Does it help?
The Block queued job plugin can be used for this: https://wiki.jenkins-ci.org/display/JENKINS/Block+queued+job+plugin

Jenkins - Put build in Queue

I want to create the following flow:
I have some program which is making a REST CALL to one of my builds, it could make it any time in a day, but i don't want this my jennkins build to be executed immediately, only in a specific interval of time E.G between 3-5 AM, but only if it has been triggered by the REST Call.
Is there any plugin or a way to do it ?
The easiest way would probably be to do some PowerShell scripting and an additional job:
Create an empty dummy job (This will be the one you trigger through the REST api)
Create another job, which will be the one you actually want to execute within a specific interval of the day. Use a Cron Build Trigger
to setup when the job should execute in case of a trigger
Using the PowerShell Plugin and Run Condition Plugin, write some PowerShell code using the Jenkins REST api to fetch information about the "dummy" job. Here you will check whether the dummy job has run (triggered) or not today, and then you can decide with the Run Condition build step, if you want to proceed with the build.

Resources