I need to capture the output of an API call that I make in task A and pass a token from the API response to another task (B). Both tasks are of type Exec. It seems that I can only get the token from task A during the execution phase, but configuring task B fails as the token is not available during configuration phase.
A simple example that demonstrates my conundrum:
task pwd(type: Exec) {
commandLine 'pwd'
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}
task lsPwd(type: Exec, dependsOn: pwd){
println "Configuration: '${pwd.output}'"
doFirst {
println "Execution First: ${pwd.output}"
}
doLast {
println "Execution Last: ${pwd.output}"
}
commandLine 'ls'
args = ['-l', '-d', "${pwd.output}"]
}
Executing task lsPwd fails as ${pwd.output} is not available when it’s configured. Commenting out the args line, I can see it output in the doFirst and doLast blocks, as I expected.
Is there any way to pass the output of an execution phase to an Exec task?
Thanks, Noel