How to add custom pipeline in azureDevops - azure-devops

i have create CI/CD pipeline in azureDevops.
i need to add custom condition for when only previous task succeeded then it will execute.
so please help me
what i have to write in Custom condition ?
I have attached below screen short where i need to add some custom condition.

i need to add custom condition for when only previous task succeeded then it will execute.
There is directly option Only when all previous tasks have succeeded, which is used to determine if all the previous tasks have succeeded.
If you want to give the condition that just when only the one previous task succeeded, there is no such out of box option to use. We could use the workaround that Napoleon answered:
write the result of the previous task to a variable and then check that variable in your condition
In addition, I posted this answer to emphasize the choice of conditions, we need use always() not succeeded() or failed(). That because the syntax of condition is for all previous steps/jobs:
Check the document Conditions for some more details.
For example:
I add three tasks in my pipeline:
Command line-Intentionally let it run failed
Run Inline Powershell-create a variable, assign it a value.
Write-Host "##vso[task.setvariable variable=TaskStatus;]Succeeded"
Command line-Custom Condition checking that variable.
and(always(), eq(variables['TaskStatus'], 'Succeeded'))
If we use the condition succeeded() or failed(), whether its execution is still affected by all previous task execution results (First command line task.)
Hope this helps.

You could write the result of the previous task to a variable and then check that variable in your condition.

i have found some custom condition which has fulfill my desire task.
in(variables['Agent.JobStatus'], 'Failed', 'Succeeded', 'SucceededWithIssues')
in above custom condition for if the prev task will 'failed' or 'succeeded' next task will executed.

Related

Until flag not working with Until activity of ADF and loop keep going

I'm trying to execute Azure Durable Function in ADF.
I have "Get Current Function Status" Activity inside Until activity. Possible value are pending, completed, running and exception. I have variable until_flag which do get value "true" if runTimeStatus get value Completed.
My problem is that even runTimeStatus is completed Until loop never stop. It keeps going. What is wrong?
I'm following tutorial https://www.youtube.com/watch?v=aD3k8k5sdao
I have tried:
#equals(bool(variables('until_flag')), 'true')
and
#bool(variables('until_flag'))
If you look into the official MS docs on UntilActivity
Enter an expression that will be evaluated after all child activities
defined in the Until activity are executed. If the expression
evaluates to false, the Until activity will execute all its child
activities again. When it evaluates to true, the Until activity will
complete. The expression can be a literal string expression, or any
combination of dynamic expressions, functions, system variables, or
outputs from other activities.
So try with this expression to evaluate condition
#equals(variables('until_flag'), 'false')

How to use OR and And operator in Custom condition in Devops Release pipeline

I'm working on a release pipeline there are many task one by one. Based on a specific task failed I have to execute a specific task to create bug.
I'm using custom condition under control option where my bug task will execute failed or succeedwithissue with status.
my condition is here:
or eq(variables['Agent.JobStatus'], 'Failed'),eq(variables['Agent.JobStatus'], 'SucceededWithIssues')and (ne(variables['varName.ActivityId'], ''))
Here I want to achieve when my previous job is failed or succeedwithissue and Activityid is not null/"" then only my bug creation task should run.
I'm getting syntax error can any one help me with.
In terms of syntax error your condition should be formatted like this:
and(or(eq(variables['Agent.JobStatus'], 'Failed'),eq(variables['Agent.JobStatus'], 'SucceededWithIssues')),ne(variables['varName.ActivityId'], ''))
the sytnax is
and(subcondition1, subcondition2)
and not
subcodntion1 and subcondition2

in build variable to detect rerun of failed builds

Is there an inbuilt pipeline or build variable to check if the run is actually a re-run of a job/stage.
I need to add this in condition as some of the steps needs to be skipped based on this variable.
- conditions: rerun()
Yes, there are variables regarding this:
System.JobAttempt - Set to 1 the first time this job is attempted, and increments every time the job is retried.
System.StageAttempt - Set to 1 the first time this stage is attempted, and increments every time the job is retried.
You can find the full variable list here.
You can use the predefinded variables System.JobAttempt or System.StageAttempt to determine if it is a re-run of a job/stage.
To skip a step if it is a re-run of a job/stage, you can set the condtion as below:
condition: eq(variables['System.JobAttempt'], '1')

Passing value from one task output to other task

Unable to find the option to pass value from one task output to other task in Azure deveops pipeline.
Pass value of Id which is an output of task to next task as an input.
task output
You can do this through Output variables part of the task.
1.Use outputs in the same job
In the Output variables section, give the producing task a reference name. Then, in a downstream step, you can use the form $(<ReferenceName>.<VariableName>) to refer to output variables.
2.Use outputs in a different job
You must use YAML to consume output variables in a different job.
For details,please refer to this document.

How to perform a conditional test within a Talend job?

I am looking to trigger a series of processes, and I want to tell if each one succeeds or fails before starting the subsequent ones.
I am using tSSH (on Talend 6.4.1) to trigger a process and I only want the job to continue if it is a success. The tSSH "component" doesn't appear to fail if it receives a non-zero return code, so I have tried using an assert. However, even if the assert fails, it doesn't appear to prevent the component and subjob being "OK" which is a bit odd, so I can't use on-(component|subjob)-ok to link to the next job.
I don't seem to be able to find any conditional evaluation components which will allow me to stop the continuation of the job or subjob based on the evaluation result.
The only way I can find is to have
tSSH1 --IF globalMap.get("tSSH_1_EXIT_CODE").equals(0)--> tSSH2...
--IF !globalMap.get("tSSH_1_EXIT_CODE").equals(0)--> (failure logging subjob)
which means coding the test twice with negation.
Am I missing something, or are there no such conditional components?
you can put a if condition on tSSH component for success /failure using global variable of tSSH component i.e.
((String)globalMap.get("tSSH_1_STDERR")) and ((String)globalMap.get("tSSH_1_STDOUT")).
if condition you can check is :
if(((String)globalMap.get("tSSH_1_STDERR")) != null) than call error log
else call tSSH2.
Hope this helps...