Skip to content

Commit 9e372c4

Browse files
author
Kevin Marquardsen
committed
Added support for executing NodeJS scripts as a build step
1 parent 091dc0c commit 9e372c4

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

docs/Home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
1717

1818
## Release Notes
1919
* 1.31 (unreleased)
20+
* Added support for the Execute NodeJS script included in the [NodeJS Plugin](https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin)
2021
* Added support for [Build Node Column Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build+Node+Column+Plugin)
2122
* Added support for [Pre-SCM Build Step Plugin](https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep)
2223
* Added support for [Sonar Plugin](http://docs.sonarqube.org/display/SONAR/Jenkins+Plugin)

docs/Job-reference.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ freeStyleJob(String name) { // since 1.30
156156
groovyCommand(String command, String groovyName, Closure groovyClosure = null)
157157
groovyScriptFile(String fileName, Closure groovyClosure = null)
158158
groovyScriptFile(String fileName, String groovyName, Closure groovyClosure = null)
159+
nodejsCommand(String command, String nodeVersion)
159160
httpRequest(String url, Closure closure = null) // since 1.28
160161
maven(Closure mavenClosure) // since 1.20
161162
maven(String target = null, String pom = null, Closure configure = null)
@@ -2209,6 +2210,18 @@ job('example') {
22092210

22102211
(since 1.27)
22112212

2213+
### NodeJS Command
2214+
```groovy
2215+
job {
2216+
steps {
2217+
nodejsCommand(String command, String nodeVersion)
2218+
}
2219+
}
2220+
```
2221+
2222+
Executes a NodeJS script. Requires the [NodeJS Plugin](https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin).
2223+
(since 1.31)
2224+
22122225
### Golang
22132226

22142227
```groovy

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/step/StepContext.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,4 +1116,20 @@ class StepContext implements Context {
11161116
}
11171117
}
11181118
}
1119+
1120+
/**
1121+
* <jenkins.plugins.nodejs.NodeJsCommandInterpreter plugin="nodejs@0.2.1">
1122+
* <command></command>
1123+
* <nodeJSInstallationName></nodeJSInstallationName>
1124+
* </jenkins.plugins.nodejs.NodeJsCommandInterpreter>
1125+
*/
1126+
void nodejsCommand(String commandScript, String installation) {
1127+
NodeBuilder nodeBuilder = new NodeBuilder()
1128+
stepNodes << nodeBuilder.'jenkins.plugins.nodejs.NodeJsCommandInterpreter' {
1129+
'command' commandScript
1130+
nodeJSInstallationName installation
1131+
}
1132+
1133+
}
1134+
11191135
}

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/step/StepContextSpec.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,4 +2451,17 @@ still-another-dsl.groovy'''
24512451
where:
24522452
mode << ['GET', 'POST', 'PUT', 'DELETE']
24532453
}
2454+
2455+
def 'call nodejsCommand method'() {
2456+
when:
2457+
context.nodejsCommand('var test = require(\'node\');', 'node (0.0.1)')
2458+
2459+
then:
2460+
context.stepNodes != null
2461+
context.stepNodes.size() == 1
2462+
def nodejsCommandStep = context.stepNodes[0]
2463+
nodejsCommandStep.name() == 'jenkins.plugins.nodejs.NodeJsCommandInterpreter'
2464+
nodejsCommandStep.command[0].value() == 'var test = require(\'node\');'
2465+
nodejsCommandStep.nodeJSInstallationName[0].value() == 'node (0.0.1)'
2466+
}
24542467
}

0 commit comments

Comments
 (0)