Run VSTS Build/Release Task only when previous task errors - azure-devops

I am trying to create a Visual Studio Team Services Extension Task for my builds and releases. I need a task that will send out an alert to another system if a previous task (including the default build/test/publish/etc.) fails.
I have already created the task to send the alert. However I do not see a way to kick off the task only if my build fails.
Is there a way in VSTS to run a task if a previous task fails, but not run it if all other tasks were successful?

It is now possible to select a running condition for all tasks with the following possible values:
Only when all previous tasks have succeeded
Even if a previous task has failed, unless the build was canceled
Even if a previous task has failed, even if the build was canceled
Only when a previous task has failed
Custom conditions
EDIT:
It is currently part of a preview, you can enable it through the "Preview features" menu after you click on your profile click on VSTS:
And activate the "New Build Editor":

There is no built-in feature.
But you can use the "Rollback" task from the Release Management Utilities to run a powershell script on failure.
https://marketplace.visualstudio.com/items?itemName=ms-devlabs.utilitytasks

Related

Run custom script in `Initialize Job` task

I have problem when build a C++ project in azure-pipeline, some dll files was access denied.
So I need to run a batch script to stop services which using these dll
I was try to run my script at pre-build event in Visual Studio but it execute after Initialize Job task, so not work
Are there any way to run script in Initialize Job?
Are there any way to run script in Initialize Job?
I am afraid there is no such way to run script in Initialize Job at this moment. The Prepare job/Initialize Job are some of the predefined work built into the pipeline. We could not add our custom script in or before those jobs.
So, to resolve this issue, we have to find the reason for this error and resolve it.
Generally, this error will most likely make an appearance if your Build and Release Agent goes offline or a build is interrupted due to an issue on the machine itself, and where specific files have been created mid-flight within the Azure Devops directory. When Azure Devops/TFS then re-attempts a new build and to write to/recreate the files that already exist, it fails, and the above error is displayed.
The best resolution is to log in to the agent machine manually, navigate to the affected directory/file (in this example, C:\VSTS\_work\xxx\xx\.tmp) and delete the file/folder in question. Removing the offending items will effectively "clean slate" the next Build definition execution, which should then complete without issue.
Hope this helps.
I had to solve this exact same problem. The solution is not ideal, but it works.
I created two pipelines. The first pipeline does any required pre-build steps, like stopping services. The second pipeline is the actual build pipeline, and it gets triggered when the first pipeline finishes. (See the build triggers section in pipeline #2.)

Is it possible to re-run Validation stage alone (without re-build) in VSTS?

Is it possible to re-run Validation stage alone (without re-build) in VSTS?
Some of our tests fail intermittently and we would like to Re-run tests (or better just the failed tests) alone to qualify pull request.
The way to re-run validation stage (part of tasks in your build definition) only in VSTS is using private agent to build, set clean as false in Get sources step and disable the tasks you want to skip. Detail steps as below:
Specify a private agent for the build definition
If you have not a private agent, you can refer the document like Deploy an agent on Windows, then specify the private agent for your build definition.
Set Clean option as false in Get sources step
In Get sources steps, set Clean option as false.
Disable the tasks you want to skip for re-build
Select the tasks you want to skip -> Disable selected task(s) -> Save build definition.
Re-build PR validation build manually
In the pull request page -> click … button -> Queue build.
Then the PR validation build will be queued with only part of tasks executed.
Recovery the build definition
After execute the validation for your debug, then you need to recover and save the build definition.

VSTS How to make a Release be triggered automatically upon successful Build completion?

I often do the following, through VSTS web UI:
Queue a build. Wait for it to finish.
If the build finished successfully, release it.
I want for step 2 to trigger automatically upon step 1 completion, so I won't have to babysit it. How can I do it?
Within your release definition:
In the old editor:
On the Artifacts tab, link the build as an artifact source
On the Triggers tab, turn on Continuous Deployment.
In the new editor:
On the pipelines tab, click the + button to add an artifact source.
Click the lightning bolt icon next to the artifact and set the Continuous Deployment trigger to enabled.
That will create a release. For any environments upon which you want to immediately start deployment, make sure the pipeline is configured so that they start after the release is created.
For the record, this is extremely well-documented.

Team Services control options in Release task

I might be doing something wrong, but I have created a Build and a Release in VSTS. For the release I need to execute a task only if one of the previous failed. This is easy for the tasks in the Build, there is a dropdown with several options including "Only when a previous task has failed", however for the release, I only have Always run and continue on error, which doesn't work for me.
Is this because the control options for release doesn't support the same options as the build or is something missing for my VSTS?
Task conditions aren't yet an option for tasks used in releases.

How execute a job from other job in Jenkins?

I have a job that updated my workspace and after will compile projects.
I need have a job (A) for update my workspace and other job (B) that first executed the job A (like a prebuild) and after will compile my project.
Under the "Build Triggers" option on the job configuration page, check the "Build after other projects are built" checkbox, and then enter the name of the precursor job in the textbox which appears. You can also configure whether you would like the job to run only if its precursor is stable, for example.
So in this case, you would configure job B to run upon completion of job A (as described above), probably requiring that job A completed successfully.