在Jenkins DSL中运行shell脚本mavenJob
问题描述:
我正在写一个Jenkins(版本2.6)DSL,它允许我检出并构建一个Maven项目,运行一个shell脚本并将其部署到Artifactory。在Jenkins DSL中运行shell脚本mavenJob
mavenJob("test-build") {
multiscm {
...
}
steps {
shell ("bash build-scripts/script.sh")
}
goals("clean install")
configure{ project ->
project/publishers << 'org.jfrog.hudson.ArtifactoryRedeployPublisher' {
details {
artifactoryUrl('<url>')
artifactoryName('<name>')
repositoryKey('libs-release-local')
snapshotsRepositoryKey('libs-snapshot-local')
}
deployBuildInfo(true)
deployArtifacts(true)
evenIfUnstable(false)
}
publishers {
archiveJunit('target/*/.xml')
publishBuilder {
discardOldBuilds(7,10)
}
}
}
的工作只有当我删除steps{}
块作为steps
不是在mavenJob
允许的工作。我试过使用freeStyleJob
,但ArtifactoryRedeployPublisher
不起作用。
我需要做些什么来运行我的shell脚本?
答
如果你想shell脚本能够提前Maven的目标运行,你可以使用这个
preBuildSteps {
// Runs a shell script.
shell(String command)
}
或者,如果你想行家进球后运行shell脚本,你可以用这一个
mavenJob('example-1') {
postBuildSteps {
shell("echo 'run after Maven'")
}
}
对于细节,你可以检查作业DSL API观众 https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.jobs.MavenJob.postBuildSteps
这是非常容易和方便的工具。
BR,
添