Maximize how you use your VSTS build and release pipeline with Inline Powershell tasks. In this blog series ‘Tips and Tricks for Inline Powershell’, I will show simple samples on how to get more out of your pipelines. This blog post: Let your task fail.
VSTS Inline Powershell task
The Inline PowerShell VSTS task enables you to execute PowerShell from a textbox within your build or release pipeline. You can run a PowerShell script on you agent or as Azure Powershell.
Introduction Inline Powershell Task
Install Inline Powershell Task
Let your Inline Powershell task fail
Sometimes you have to fail your build or release. In your Inline Powershell task you have 2 options in bow to do this. The first option in with a ‘exit 1’, the second option is vso command.
exit 1
Write-Host "##vso[task.complete result=Failed;]DONE"
You have to following options as result value for your task:
Succeeded
SucceededWithIssues
Failed
Cancelled
Skipped
More tips and tricks
Use VSTS variables
Let your task fail
Set progress
Change buildnumber
VSTS Command overview
Call a WebHook
Download a file
Install a Powershell Module
Navigate VSTS as filesystem
Make VSTS API Rest calls
Script example: Act on failed build
Hi
Again thanks for the Task you created it is great!
Is it possible to get the last task result and use it in the next task?
Do i need to set my own variable for this or is there a system variable?
I need to know if former task failed and then decide what to do with current task
thanks
gal
LikeLike
You can manage variables from powershell: https://pgroene.wordpress.com/2017/12/07/use-vsts-variables-inline-powershell
React on a failed task (do not forget to mark the task as always run): https://pgroene.wordpress.com/2017/12/21/let-your-build-work-for-you-shorten-the-feedback-loop
LikeLike
Hi
What i am trying to get is the result of the build – using task “Visual Studio Build”
I want to trigger an event on that fail
Is there an option\parmeter to get Last Task Result?
Thanks
Gal
LikeLike
You can find a sample in this post https://pgroene.wordpress.com/2017/12/21/let-your-build-work-for-you-shorten-the-feedback-loop/
LikeLike
Hi
Sorry to trouble you
I am trying to get the result of a build task during the build not after build fails .
Is that possible?
Thanks
Gal
LikeLike
That is exactly what in the sample of my previous comment. Get the current build status with the cats apis. You get can get the build results on task level of you current build.
LikeLike
a 3rd option is to use the throw command:
Throw “I purposely killed the build!”
LikeLike
This is good, but I’d really like to be able to conditionally pass my build without executing any more steps. Or conditionally execute a following step. Is this possible? Thanks!
LikeLiked by 1 person
Yes, if you write:
Write-Host “##vso[task.complete result=Failed;]DONE”
to the output the build will fail. You can do that on any variable check or condition you want. Only if configure the next steps to execute even if the build is failed, these steps will run.
LikeLike