Azure cron pipeline always runs - azure

I have set up an Azure pipeline to run GUI tests twice a day. According to the documentation, it should only run if there have been code changes, but it always runs.
This is my cron schedule in "azure-pipelines-cypress.xml"
schedules:
- cron: "0 10 * * *"
displayName: Daily 12:00 build (UTC 10:00)
branches:
include:
- master
Note that the documentation (https://learn.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml#scheduled-triggers) states:
always: boolean # whether to always run the pipeline or only if there have been source code changes since the last run. The default is false.
Is this simply a bug or am I missing something?

Azure cron pipeline always runs
Update2:
I don't want it to run every time the master branch is updated. It
should run when the master branch is updated AND only at a scheduled
time.
But is that not the expected behavior of my current pipeline? The
current behavior acts as if I had set "always: true"
First of all, thanks Mick for your patience in providing a lot of detailed information.
Now, I figure out the issue and I could reproduce this issue on my side. If we set the scheduled triggers, but the build result is failed. In this case, even if we do not any change, the scheduled triggers will still fire. That because the latest build failed, so the last commit record was not recorded by the pipeline. When the scheduled time is reached, the last commit/source code change still exists. It will trigger scheduled triggers.
So, that the reason why your pipeline still executed, even if you do not do any change in the code/yaml.
If I successfully build the pipeline, the scheduled triggers works as expected.
So, it should be said that the documentation is not clear enough, it should be:
always: boolean # whether to always run the pipeline or only if there
have been source code changes since the last successful run. The
default is false.
I submit this to MS, Thank you for helping us build a better Azure DevOps.
Hope this helps.

Related

How to debug Gitlab CI scheduled pipeline not running?

I have a Gitlab CI pipeline schedule and noticed that pipelines are not running (anymore).
When starting the schedule manually via the UI (<repo-root>/-/pipeline_schedules) it shows the following
However, there is not pipeline started and no error message is provided.
What can I do in this situation?
The success message is misleading in the sense that one might thing the pipeline was actually created, although it only means that a pipeline was scheduled.
There are various reasons, why a schedule cannot run (anymore).
This can be for example because of conflicting rules or outdated fields in your yml caused by breaking changes due to Gitlab upgrades.
To get to the root of the problem why your pipeline did not run you can trigger a pipeline manually and set the
CI_PIPELINE_SOURCE to hold "schedule" as value.
To do so, go to <repo-root>/-/pipelines/new, set your target branch or tag and the variable as follows
Additionally, you may want to provide further variables required to properly simulate your problematic schedule via the manual run.
Next hit Run pipeline and you should observe an actual error message why the pipeline could not run.

Schedule.create triggers an unwanted pipeline run immediately after publish

I am using azureml schedules to schedule azureml pipelines. When I want to update a pipeline I am disabling the schedule, deleting and re-publishing the updated pipeline and re-creating the schedule. However every time I do this, the schedule.create command sets the pipeline running as soon as it is published (instead of just setting it to run at the provided recurrence intervals).
Can I disable this behaviour? I dont need the pipeline to automatically run every time I commit and re-run the publish pipelines

Is there any way to rollback devops pipeline on last successful?

I am trying to rollback in release pipeline when the latest release gets fail it will revert at last successful. I added a PowerShell task which only runs when previous tasks have failed and script which is triggering last successful but the problem is it start redeploying stages randomly not sequentially.## Heading ##
In my scenario I have 3 stages, at the end of each stage, I have added a PowerShell task that will trigger only when the previous task has failed and wrote a script accordingly to trigger last successful release. so it will trigger all the stages in the last release because I haven't got any API or command to trigger release by id. I have an API which triggers only stages. All the stages are queueing sequentially but running randomly.
enter image description here
Since you are using the Release Pipeline, I suggest that you could use Auto-redeploy trigger option for each stage.
When the stage fails, it will re-deploy the last successful release of the current stage.
For example:
Set Auto-redeploy trigger option for stage 2 -> Stage2 fail -> Auto redeploy the last successful Stage 2
Update:
From you requirement, you could try to use the Release Orchestratortask from Release Orchestrator extension. This task could be used to manage the release.
Here is the example:
You could use this task to replace the powershell task. This task supports to select the re-run release name and the target stages.
It can also be sorted according to the input stage order.
Note: you also need to set Maximum number of parallel deployments as 2 for each stage -> Pre-deployment conditions-> Deployment queue settings.

Azure DevOps Pipeline build triggering unexpectedly

Updated 26-Feb-2020
In our Project, I have a pipeline "MyPipeline" which restores the NuGet packages, builds the solutions and runs the tests.
On the master branch, I have a policy which does things like add code reviewers, and it has a "build validation" step which executes "MyPipeline". All well and good.
However, I created another branch from Master called NewBranch and synced (pushed) this up to Azure. After doing some minor changes in Visual Studio, I did a merge from master, committed and sync'd to Azure.
I was a bit surprised then to see "MyPipeline" executing. It seems to have been triggered when I pushed my changes to NewBranch to Azure. I don't have a branch policy on "NewBranch". The trigger in the YAML file is:
trigger:
- master
What kicked this off? I'll soon burn through my free agent minutes if this continues...
Update 26-Feb-2020
As per the comments below:
The history of commits on the master branch are:
Tue 9:10 PM
Tue 7:47 PM
Mon 2:46 PM
The history of the pipeline execution show:
Wed 9:14 AM "PR Automated"
So, nothing new has been committed to the Master branch. However, I think I know what's causing this. Just that I'm not convinced on the timing....
So, we have two branches, master and NewBranch.
Master has a policy that requires two code reviewers to Approve, and it requires the build to succeed. Because of this policy, a developer can't therefore merge directly into master - they have to generate a Pull Request.
So, Developer A creates a Pull Request to merge NewBranch to Master. There is then the rather lengthy code review process which may take multiple additional commits to the "NewBranch"'s Pull Request before it's deemed acceptable.
What seems to be happening is that everytime one of these new Commits is sync'd to the Pull Request, a build is triggered. Is this a good thing? Maybe, Maybe not. If the build is going to trigger just once, then the compilation should occur when all the code in the Pull Request has been approved, not before hand. Why trigger a build at such an early stage; the master branch may be updated by multiple other Pull Requests before this is ready to be merged in. However, with unlimited resources, then I guess there's no harm in building as often as possible, but a) this can delay other builds (representing an impediment to other developers) and b) this uses up the free limit on agent time.
The detailed info you share in question is much help for me to understand the whole workflow of yours.
Though you did not express too clear, but, yeah, what you are guessing is correct. The action you faced is expected and by designed. The root cause is you are using branch policy and the Build validation also included into this policy.
The nutshell is you are using Pull request trigger.
Explanation:
Let's pay attention to its definition:
Pull request (PR) triggers cause a build to run whenever a pull request is opened with one of the specified target branches, or when
changes are pushed to such a pull request.
Based on your added contents, your developers are pushing changes (new commit) into the opening Pull request (Note: The key point is Pull request is still be opening.) This belongs to the work scope of the PR trigger because of above definition. That is why the build triggered every y new changes pushed into NewBranch branch.
Work around:
I agree with the logic of #devpro's answer. But its script does not available for your scenario. Because the pr in YAML only work for GitHub and Bitbucket Cloud repos.
Here you are using VSTS repo, and configured the policy for it. So, you can only via branch policy configuration to avoid such burning trouble.
In your Build validation panel, you are setting build policy with Automatic, right?
Please change the Automatic to Manual, also keep the Policy requirement value as Required.
Now, the corresponding build pipeline will not be ran automatically once new commit pushed, it can only built when someone run it manually.
For the delay timing you noticed which make you unsure, I guess it would because of conflict.
For sample, the Pull request P1 which merge from NewBranch to Master is opening. I commit a new change C1 into NewBranch. BUT, it causes the conflict. At this time, the build will not be ran because the changes does not actually pushed into PR.
Note: The commit is true to NewBranch. BUT changes does not accepted by PR yet, because PR detect out there has conflict here and you must tell PR which changes you want to keep. Only the changes pushed into PR can work with PR trigger.
Only the conflict solved, the changes, maybe I can say commit, can truly be accepted and pushed into PR. Then the triggered build ran.
This would be the time period delay you noticed.
I've seen the same behaviour today.
Can you try rewriting the trigger part in your pipeline like this:
trigger:
branches:
include:
- master
Does that help ? I can't verify it myself yet, since I've done that change but the PullRequest isn't approved yet :)
I've also another repository where I do not see that behaviour, but there, my pipeline trigger looks like this:
trigger:
- master
(Notice the 2 spaces before - master)
I think you need to add pr: none to your pipeline definition to disable the automated run.
If pr is not set I think the default is to run on every PR.
That would give something like this:
trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- README.md
pr: none

Azure Pipelines DevOps Not Being Triggered by PR

I've been using Azure Pipelines for a while now and haven't changed my azure-pipelines.yml file here in 2 months. Previously, when there was a new PR, the pipeline would trigger and cause the environment to be built and the tests would be run.
Today, there was a new PR but I noticed that the pipeline was not being triggered. Then, to further test this, I forked, cloned, and branched the repository myself and created another new PR and, again, the pipeline was not triggered.
It's not clear to me where things are getting stuck and it's not clear how one would debug this. I've gone through this Azure DevOps documentation but it wasn't useful. I can manually trigger the pipeline to execute and test the master branch but I don't know how to manually trigger the same thing for a PR. Here's my Azure DevOps page for reference.
As normal, you do not need config pr in YAML script if there's no any special demand, we would do pull request trigger for all branches. But, it start broken from 03-13 21:02 (UTC), which caused by us, you do not do anything wrong.
The fix is preparing with our best.
As Alex said, this is the implicit trigger which YAML support only, if you do not configure pr in YAML explicitly.
To avoid such stuck later, except the method that Alex mentioned: add pr into YAML. You can also make use of UI configuration which performance is very stable until now.
Just go Pipeline definition page => Click on three dots of right corner => Select Trigger:
Then you will see Triggers tab which has Continues integration and Pull request validation display below. Open Pull request validation and enable Override the YAML pull request trigger from here:
Additional, Our team has noticed this broken issue, will update whether it is fixed here once we have any fixed release in progress.
Update 3/18/2020:
Fixed has released to all region. Every one can work github pr trigger as the document shows now.

Resources