diff --git a/src/main/groovy/com/lesfurets/jenkins/unit/declarative/AgentDeclaration.groovy b/src/main/groovy/com/lesfurets/jenkins/unit/declarative/AgentDeclaration.groovy index 23c6137b..db370f43 100644 --- a/src/main/groovy/com/lesfurets/jenkins/unit/declarative/AgentDeclaration.groovy +++ b/src/main/groovy/com/lesfurets/jenkins/unit/declarative/AgentDeclaration.groovy @@ -77,7 +77,7 @@ class AgentDeclaration extends GenericPipelineDeclaration { def execute(Object delegate) { def agentDesc = null - if (label) { + if (label != null) { agentDesc = '[label:' + label.toString() + ']' } else if (docker) { diff --git a/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy b/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy index 56a5a98a..ecdfeca3 100644 --- a/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy +++ b/src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy @@ -647,4 +647,12 @@ class TestDeclarativePipeline extends DeclarativePipelineTest { assertCallStack().contains('echo(Deploy to someLabel)') assertJobStatusSuccess() } + + @Test void should_agent_with_empty_label() throws Exception { + runScript('AgentEmptyLabel_Jenkinsfile') + printCallStack() + assertCallStack().contains('[label:]') + assertCallStack().contains('echo(Hello using custom workspace and empty label)') + assertJobStatusSuccess() + } } diff --git a/src/test/jenkins/jenkinsfiles/AgentEmptyLabel_Jenkinsfile b/src/test/jenkins/jenkinsfiles/AgentEmptyLabel_Jenkinsfile new file mode 100644 index 00000000..71d1802c --- /dev/null +++ b/src/test/jenkins/jenkinsfiles/AgentEmptyLabel_Jenkinsfile @@ -0,0 +1,15 @@ +pipeline { + agent { + node { + label '' + customWorkspace "myworkspace" + } + } + stages { + stage('Example Build') { + steps { + echo "Hello using custom workspace and empty label" + } + } + } +}