in build variable to detect rerun of failed builds - azure-devops

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')

Related

How to build OR-behavior into Azure Synapse pipelines?

I have a pipeline in Synapse that reloads data from a number of REST-endpoints. It looks as follows:
What I want to achieve is that the 'CheckAccessTokenValidity' activity checks whether my API-token is still valid. If yes, all is fine, proceed to ForEachDivision activity. If no, refresh tokens, Proceed to ForEachDivision activity.
I thought I had implemented this logic in the screenshot provided. However, this is not the case. My pipeline is now deadlocked because the ForEachDivision apparently expects all three preceding activities to be succesful before running (Which is impossible by design).
How do I implement the logic described above in Azure Synapse?
You can modify your pipeline and accommodate following changes:
Create a variable 'var1' , by default set it to 'False'
After 'CheckAccessTokenValidity' , add set variable activity 'set variable1' pointing to 'var1' and set its value as 'True'
After SetRefreshToken , add another set variable activity 'set variable2' pointing to same 'var1' and set its value as 'True' , so that either of the step 2 or 3 can turn the value of variable to 'True'.
Remove all activities starting ForEach block from this pipeline and cut paste those activities and keep in another new pipeline 'pipeline2'
After 'set variable2' activity, attach an If activity with 'success' and 'Skipped' conditional path . If step 2 gets successful, 'set variable2' would be skipped and it will call the next activity that is 'Step6' . If step 2 fails, and step 3 is called, it will call 'set variable2' and after its success, Step6 will be completed.
In this if activity, write the condition to check the value of var1 . If var1=='True' , then execute the 'pipeline2'

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 add custom pipeline in azureDevops

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.

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...

Rundeck[passing parameters between the jobs]

I have a job which calls another rundeck job, I want to pass parameters between the jobs. I can only pass options from the 1st job to 2nd job, i want results(output) of the 1st job to be passed to the second job as an argument.
Example: 1st job content.
set -x;
sql_file=/apps/$env/test${buildnumber}.sql;
echo $sql_file
I want to call 2nd job, and pass sql_file location as the variable
I can refer the 2nd job and give options of the 1st job as an argument, i cannot find a way to give the output of the 1st job as an arguemnt to the 2nd job.
Rundeck 2.9 will support this ability. It is not released yet, but you can try the beta version here http://rundeck.org/news/2017/06/20/rundeck-2.9.0-beta1.html