pipeline {
agent {
- // This label should match an agent available on the target system
- label "centos7-docker-4c-2g"
+ node {
+ // This label should match an agent available on the target system
+ label "centos7-docker-4c-2g"
+ }
}
options {
lfJava(mvnSettings=env.mvnSettings)
}
}
+ stage("Node Verify") {
+ steps {
+ lfNode()
+ }
+ }
stage("Parallel Testing") {
parallel {
stage("amd") {
--- /dev/null
+######
+lfNode
+######
+
+Parameters
+==========
+
+:Optional Parameters:
+
+ :nodeDir: Root of NodeJS project.
+ :nodeVersion: The version of NodeJS to use. This must be installed in
+ Jenkins' global tools.
+
+Usage
+=====
+
+Calling lfNode will execute a simple ``npm install`` followed by ``npm test`` in
+order to validate the code.
--- /dev/null
+---
+features:
+ - |
+ Add the lfNode job, which replicates the functionality of the global-jjb
+ ``node-verify`` job.
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0
+//
+// Copyright (c) 2021 The Linux Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification
+
+public class LFNodeSpec extends JenkinsPipelineSpecification {
+
+ def lfNode = null
+ def defaults = [
+ nodeDir: "",
+ nodeVersion: "14.17.5",
+ ]
+
+ def setup() {
+ lfNode = loadPipelineScriptForTest("vars/lfNode.groovy")
+ explicitlyMockPipelineVariable("lfDefaults")
+ }
+
+ def "Test lfNode [Should] build NodeJS [When] called" () {
+ setup:
+ explicitlyMockPipelineStep("dir")
+ explicitlyMockPipelineStep("nodejs")
+ getPipelineMock("lfDefaults.call")() >> {
+ return defaults
+ }
+ when:
+ lfNode()
+ then:
+ 1 * getPipelineMock("dir").call(_)
+ 1 * getPipelineMock("nodejs").call(_) >> { _arguments ->
+ assert _arguments[0][0]["nodeJSInstallationName"] == defaults["nodeVersion"]
+ assert _arguments[0][0]["configId"] == "npmrc"
+ }
+ 1 * getPipelineMock("sh").call("npm install")
+ 1 * getPipelineMock("sh").call("npm test")
+ }
+}
mvnGoals: "clean install",
mvnVersion: "mvn35",
mvnGlobalSettings: "global-settings",
+
+ nodeDir: "",
+ nodeVersion: "14.17.5",
]
return defaults
}
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0
+//
+// Copyright (c) 2021 The Linux Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * Method to run Node jobs.
+ * Optional body values (should be defined in lfDefaults):
+ * * nodeDir
+ * * nodeVersion
+ *
+ * @param body Config values to be provided in the form "key = value".
+ */
+def call(body) {
+ // Evaluate the body block and collect configuration into the object
+ def defaults = lfDefaults()
+ def config = [:]
+
+ if (body) {
+ body.resolveStrategy = Closure.DELEGATE_FIRST
+ body.delegate = config
+ body()
+ }
+
+ // For duplicate keys, Groovy will use the right hand map's values.
+ config = defaults + config
+
+ ///////////////////
+ // Verify NodeJS //
+ ///////////////////
+ dir(config.nodeDir) {
+ // The nodeJS installation configured in Jenkins' Global Tools should
+ // be named simply with the version.
+ nodejs(nodeJSInstallationName: config.nodeVersion, configId: "npmrc") {
+ sh "npm install"
+ sh "npm test"
+ }
+ }
+}