Passing value from one task output to other task - azure-devops

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.

Related

Azure pipeline parameter split doesn't work

I have a mutli-step azure pipeline used to trigger the execution of a certain job based on keywords I have in azure devops work items.
First step executed is a powershell script that stores into a 'validTags' variable a comma-separated list of strings:
Write-Host "##vso[task.setvariable variable=validTags]$csTags"
After this step, I correctly see the list formatted as I expect:
string1,string2,string3
The 'validTags' variable is then passed as a parameter to another pipeline in which I should split this list and trigger separate jobs:
- template: run.yml
parameters:
tags: $(validTags)
directory: 'path\to\tests'
platforms: 'platform1,platform2'
In the 'run' pipeline I defined this 'tags' parameter:
parameters:
- name: tags
type: string
default: 'someDefaultValue'
and I try to split the parameter:
- ${{each t in split(parameters.tags, ',')}}:
- script: |
echo 'starting job for ${{t}}'
but when I execute the pipeline, I have in 't' still the full string (string1,string2,string3) not splitted.
I have noticed that if I try to perform the split on the "platforms" parameter which is passed along with "tags" to the run.yml pipeline, it works, so it seems that the problem is related to the fact that I am trying to split a string stored in an external variable?
Anyone with a similar issue? Any help on this is much appreciated.
Thanks
For those interested in the outcome of this issue:
I tested several possible alternate solutions, including the use of global variables and group variables, but without success.
I submitted a request to MSFT engineering support to get some insight on this and their response is:
The pipeline does not support splitting the runtime variable with
template syntax ${{ }} currently, and we are not able to find other
workarounds to meet your request. Sorry for the inconvenience. Hope
you can understand.
So, to overcome the issue I removed the split at the pipeline level, as initially planned, but rather passed the comma-separated value's string to the template and added there the necessary processing in Powershell.
Another option would have been to perform all the operations from within the first PowerShell script step:
transform the 'run.yml' template in a separate pipeline
in the script, after getting the tags, loop over their values and trigger the 'run.yml' pipeline passing the single tag as a parameter.
I avoided this solution to keep the operations separate and have more control over the execution flow.

Rundeck Community passing variable/parameter between job

I have job in rundeck inline script where I have defined variable like
Job1:
ABC="xyz"
echo "ABC=$ABC"
Now,I would like to call this job in another job(like job2) and want to print the value of ABC.
How can I catch the value of 'ABC' in another job's inline script?
The easier way is to pass that data value by creating an option on the second job to "receive" the data generated by the first job. That was answered here.

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.

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

Can a list of strings be supplied to Capistrano tasks?

I have a task whose command in 'run' is the same except for a single value. This value would out of a list of potential values. What I would like to do is create a task which would use this list of values to define the task and then use that same value in the command defined in 'run'. The point is that it would be great to define the task in such a way where I don't have to repeat nearly identical task definitions for each value.
For example: I want a task that will get the status of a single program from a list of programs that I have defined in an array. I would like to define task to be something like this:
set programs = %w["postfix", "nginx", "pgpool"]
programs.each do |program|
desc "#{program} status"
task :#{program} do
run "/etc/init.d/#{program} status"
end
end
This obviously doesn't work, but hopefully it shows what I am attempting here.
Thoughts?
Well, I answered my own question... with a little trial and error. I also did the same thing with namespace so the control of services is nice and elegant. It works quite nicely!
set :programs, %w[postfix nginx pgpool]
set :init_commands, %w[status start stop]
# init.d service control
init_commands.each do |init_command|
namespace :"#{init_command}" do
programs.each do |program|
desc "#{program} #{init_command}"
task :"#{program}" do
run "/etc/init.d/#{program} #{init_command}"
end
end
end
end