diff --git a/src/test/groovy/WithNodeStepTests.groovy b/src/test/groovy/WithNodeStepTests.groovy index bf7c02f2a..b53a3a11b 100644 --- a/src/test/groovy/WithNodeStepTests.groovy +++ b/src/test/groovy/WithNodeStepTests.groovy @@ -47,7 +47,7 @@ class WithNodeStepTests extends ApmBasePipelineTest { } printCallStack() assertTrue(isOK) - assertTrue(assertMethodCallContainsPattern('node', 'foo && extra/')) + assertFalse(assertMethodCallContainsPattern('node', 'foo && extra/')) assertTrue(assertMethodCallOccurrences('ws', 0)) assertJobStatusSuccess() } @@ -67,6 +67,33 @@ class WithNodeStepTests extends ApmBasePipelineTest { assertJobStatusSuccess() } + @Test + void test_with_forced_worker() throws Exception { + helper.registerAllowedMethod('isStaticWorker', [Map.class], { return false }) + def isOK = false + script.call(labels: 'foo', forceWorker: true) { + isOK = true + } + printCallStack() + assertTrue(isOK) + assertTrue(assertMethodCallContainsPattern('node', 'foo && extra/')) + assertJobStatusSuccess() + } + + @Test + void test_with_forced_static_worker() throws Exception { + helper.registerAllowedMethod('isStaticWorker', [Map.class], { return true }) + def isOK = false + script.call(labels: 'arm', forceWorker: true) { + isOK = true + } + printCallStack() + assertTrue(isOK) + assertTrue(assertMethodCallContainsPattern('node', 'arm')) + assertFalse(assertMethodCallContainsPattern('node', 'extra/')) + assertJobStatusSuccess() + } + @Test void test_with_forced_workspace() throws Exception { helper.registerAllowedMethod('isStaticWorker', [ Map.class ], { return false }) diff --git a/vars/README.md b/vars/README.md index 559909b3a..6a6e6483e 100644 --- a/vars/README.md +++ b/vars/README.md @@ -1315,8 +1315,8 @@ Wrapper to interact with the gsutil command line. It returns the stdout output. Check if the author of a GitHub comment has admin or write permissions in the repository. ``` -if(!hasCommentAuthorWritePermissions(repoName: "elastic/beats", commentId: env.GT_COMMENT_ID)){ - error("Only Elasticians can do this action.") +if(!hasCommentAuthorWritePermissions(repoName: "elastic/kibana", commentId: env.GT_COMMENT_ID)){ + error("Only Elasticians can deploy Docker images") } ``` @@ -2917,7 +2917,7 @@ Wrap the node call for three reasons: } // Use ephemeral worker with a sleep of up to 100 seconds and with a specific workspace. - withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true){ + withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true, forceWorker: true){ // block } ``` @@ -2925,7 +2925,8 @@ Wrap the node call for three reasons: * labels: what's the labels to be used. Mandatory * sleepMin: whether to sleep and for how long at least. Optional. * sleepMax: whether to sleep and for how long maximum. Optional. -* forceWorkspace: whether to allocate a new unique workspace. Optional. +* forceWorker: whether to allocate a new unique ephemeral worker. Optional. Default false +* forceWorkspace: whether to allocate a new unique workspace. Optional. Default false ## withNpmrc Wrap the npmrc token @@ -3015,3 +3016,4 @@ writeVaultSecret(secret: 'secret/apm-team/ci/temp/github-comment', data: ['secre * secret: Name of the secret on the the vault root path. Mandatory * data: What's the data to be written. Mandatory + diff --git a/vars/withNode.groovy b/vars/withNode.groovy index e5c5a2ebb..43319568b 100644 --- a/vars/withNode.groovy +++ b/vars/withNode.groovy @@ -27,7 +27,7 @@ Wrap the node call for three reasons: } // Use ephemeral worker with a sleep of up to 100 seconds and with a specific workspace. - withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true){ + withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true, forceWorker: true){ ... } */ @@ -36,13 +36,17 @@ def call(Map args = [:], Closure body) { def sleepMax = args.get('sleepMax', 0) def labels = args.containsKey('labels') ? args.labels : error('withNode: labels parameter is required.') def forceWorkspace = args.get('forceWorkspace', false) + def forceWorker = args.get('forceWorker', false) def uuid = UUID.randomUUID().toString() // Sleep to smooth the ram up with the provisioner sleep(randomNumber(min: sleepMin, max: sleepMax)) // In case of ephemeral workers then use the uuid - def newLabels = isStaticWorker(labels: labels) ? labels : (labels?.trim() ? "${labels} && extra/${uuid}" : "extra/${uuid}") + def newLabels = labels + if (forceWorker) { + newLabels = isStaticWorker(labels: labels) ? labels : (labels?.trim() ? "${labels} && extra/${uuid}" : "extra/${uuid}") + } log(level: 'INFO', text: "Allocating a worker with the labels '${newLabels}'.") node("${newLabels}") { diff --git a/vars/withNode.txt b/vars/withNode.txt index b88e7962c..4e6e6c7ef 100644 --- a/vars/withNode.txt +++ b/vars/withNode.txt @@ -11,7 +11,7 @@ Wrap the node call for three reasons: } // Use ephemeral worker with a sleep of up to 100 seconds and with a specific workspace. - withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true){ + withNode(labels: 'immutable && ubuntu-18', sleepMax: 100, forceWorspace: true, forceWorker: true){ // block } ``` @@ -19,4 +19,5 @@ Wrap the node call for three reasons: * labels: what's the labels to be used. Mandatory * sleepMin: whether to sleep and for how long at least. Optional. * sleepMax: whether to sleep and for how long maximum. Optional. -* forceWorkspace: whether to allocate a new unique workspace. Optional. +* forceWorker: whether to allocate a new unique ephemeral worker. Optional. Default false +* forceWorkspace: whether to allocate a new unique workspace. Optional. Default false