Skip to content

Commit

Permalink
fix(buildPlugin) ensure the custom label is passed to node when addin…
Browse files Browse the repository at this point in the history
…g custom platform (jenkins-infra#658)

Signed-off-by: Damien Duportal <[email protected]>
  • Loading branch information
dduportal authored and smerle33 committed Jan 16, 2024
1 parent a94c6b8 commit 2dd0c33
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
36 changes: 32 additions & 4 deletions test/groovy/BuildPluginStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,45 @@ class BuildPluginStepTests extends BaseTest {
// when running without any parameters
script.call([:])
printCallStack()
// then it runs in a linux node
assertTrue(assertMethodCallContainsPattern('node', 'linux'))
// then it runs in a windows node
assertTrue(assertMethodCallContainsPattern('node', 'windows'))
// then it runs a stage in a linux VM by default
assertTrue(assertMethodCallContainsPattern('node', 'vm && linux'))
// then it runs a stage in a Windows VM by default
assertTrue(assertMethodCallContainsPattern('node', 'docker-windows'))
// then it runs the junit step by default
assertTrue(assertMethodCall('junit'))
// then it runs the junit step with the maven test format
assertTrue(assertMethodCallContainsPattern('junit', '**/target/surefire-reports/**/*.xml,**/target/failsafe-reports/**/*.xml'))
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_container_agents() throws Exception {
def script = loadScript(scriptName)
// when running with useContainerAgent set to true
script.call([useContainerAgent: true])
printCallStack()
// then it runs a stage in a linux container by default
assertTrue(assertMethodCallContainsPattern('node', 'maven'))
// then it runs a stage in a Windows container by default
assertTrue(assertMethodCallContainsPattern('node', 'maven-windows'))
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_customplatforms() throws Exception {
def script = loadScript(scriptName)
// when running with useContainerAgent set to true
script.call(platforms: ['openbsd', 'maven-windows-experimental'])
printCallStack()
// then it runs a stage in an openbsd node with a warning message
assertTrue(assertMethodCallContainsPattern('node', 'openbsd'))
assertTrue(assertMethodCallContainsPattern('echo', 'WARNING: Unknown Virtual Machine platform \'openbsd\''))
// then it runs a stage in a maven-windows-experimental node with a warning message
assertTrue(assertMethodCallContainsPattern('node', 'maven-windows-experimental'))
assertTrue(assertMethodCallContainsPattern('echo', 'WARNING: Unknown Virtual Machine platform \'maven-windows-experimental\''))
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_timeout() throws Exception {
def script = loadScript(scriptName)
Expand Down
4 changes: 2 additions & 2 deletions vars/buildPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def call(Map params = [:]) {
label = 'vm && linux'
break
default:
echo "WARNING: Unknown platform '${platform}'. Agent label set to fallback value 'linux'"
label = 'linux'
echo "WARNING: Unknown Virtual Machine platform '${platform}'. Set useContainerAgent to 'true' unless you want to be in uncharted territory."
label = platform
}
}

Expand Down

0 comments on commit 2dd0c33

Please sign in to comment.