JenkinsPipelineUnit
JenkinsPipelineUnit copied to clipboard
How to assert the agent label of a DeclarativePipelineTest?
I have a jenkins pipeline script with a specified agent label, similar to the one below. Is it possible to write a test (inheriting from DeclarativePipelineTest
) which will assert the label the code was executed on?
pipeline {
agent {
label 'windows'
}
options {
...
}
...
If I'm correct, the PipelineTestHelper.callStack
field does not contain any agent info.
AgentDeclaration.execute prints agent information in the call stack.
Something like: Agent_bindings_Jenkinsfile.echo(Executing on agent [label:someLabel])
And due to the echo ending in println: Executing on agent [label:someLabel]
I think it is a good idea to add some log message to the callstack when it processing agent closure