JenkinsPipelineUnit icon indicating copy to clipboard operation
JenkinsPipelineUnit copied to clipboard

How to assert the agent label of a DeclarativePipelineTest?

Open topalach opened this issue 4 years ago • 2 comments

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.

topalach avatar Sep 08 '20 12:09 topalach

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]

Willem1987 avatar Sep 17 '20 10:09 Willem1987

I think it is a good idea to add some log message to the callstack when it processing agent closure

stchar avatar Sep 27 '20 11:09 stchar