Skip to content

Instantly share code, notes, and snippets.

@rochejul
Last active July 10, 2020 12:44
Show Gist options
  • Save rochejul/5e020248b47ccbf29578a5dac521c2d7 to your computer and use it in GitHub Desktop.
Save rochejul/5e020248b47ccbf29578a5dac521c2d7 to your computer and use it in GitHub Desktop.
Groovy script for Jenkins, for "Inject environment variables to the build process" to retrieve the version of the current package.json file (for NodeJs)
import groovy.json.JsonSlurper
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
def build = Thread.currentThread().executable
def inputFile = new File(build.workspace.toString() + "/package.json")
def InputJSON = new JsonSlurper().parseText(inputFile.text)
def map = [PACKAGE_VERSION: InputJSON.version]
return map
@rochejul
Copy link
Author

Exposed as "PACKAGE_VERSION" environment variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment