Groovy web console

subscribe to the feed Subscribe
to this
site

example

Published 1 month ago by bool with tags jenkins groovy template
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def app = [name: 'some-app', cmd: 'package', outputs: ['target/1.ear', 'target/2.ear', 'module-xxfnkn/target/3.ear']]

def template = new groovy.text.SimpleTemplateEngine().createTemplate '''
def onDistrib(app, distr) {
  withMaven(jdk: "$jdk", maven: "$maven", mavenSettingsConfig: "$mavenSettingsConfig") {
    sh script: "mvn $mavenCmd" // команда для сборки дситрибутива
  }
${outputs.collect{"  distr.addBH('$it')"}.join('\\n')}
}
return wrapJenkinsfile(this)
'''

def binding = [jdk: '1.8', maven: 'maven-3.5', mavenSettingsConfig: 'maven-settings', mavenCmd: "mvn $app.cmd", outputs: app.outputs]
def content = template.make(binding).toString()
content