运行 奴隶上的詹金斯 DSL 脚本
run jenkins DSL script on slave
我有一个 Build Flow 项目,其中包含用于配置流程的 DSL 脚本。
这是我的脚本:
def envVars = build.getEnvironment(listener)
def revision = envVars.get("GIT_COMMIT")
def workspace = envVars.get("WORKSPACE")
println "env vars: " + envVars
println "workspace: " + workspace
println "revision: " + revision
def command = workspace+"""/scripts/my_script.sh"""
def proc = command.execute()
proc.waitFor()
println "return code: ${proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}"
parallel (
{
build("job1", git_branch: revision)
},
{
build("job2", git_branch: revision)
},
{
build("job3", git_branch: revision)
}
)
在我的工作配置中,我检查了 Restrict where this project can be run
并给出了正确的从属标签。
我的作业因以下错误而失败:
ERROR: Failed to run DSL Script
java.io.IOException:
Cannot run program "/home/jenkins/workspace/my-flow-job/scripts/my_script.sh":
error=2, No such file or directory
我发现 DSL 脚本 运行ning 在主节点而不是从节点上。
我如何运行 从站上的 DSL? (或者至少在从机上执行脚本)
谢谢
您应该为当前频道创建一个文件路径并创建一个启动器来启动您的脚本。像下面这样的东西应该适合你。
def envVars = build.getEnvironment(listener)
def workspace = envVars.get("WORKSPACE")
def command = workspace+"""/scripts/my_script.sh"""
def channel = build.workspace.channel
def fp = build.workspace.toString()
def workspacePath = new hudson.FilePath(channel, fp)
def launcher = workspacePath.createLauncher(hudson.model.TaskListener.NULL);
def starter = launcher.launch().pwd(workspacePath).stdout(out).stderr(out).cmdAsSingleString(command)
starter.join()
我有一个 Build Flow 项目,其中包含用于配置流程的 DSL 脚本。
这是我的脚本:
def envVars = build.getEnvironment(listener)
def revision = envVars.get("GIT_COMMIT")
def workspace = envVars.get("WORKSPACE")
println "env vars: " + envVars
println "workspace: " + workspace
println "revision: " + revision
def command = workspace+"""/scripts/my_script.sh"""
def proc = command.execute()
proc.waitFor()
println "return code: ${proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}"
parallel (
{
build("job1", git_branch: revision)
},
{
build("job2", git_branch: revision)
},
{
build("job3", git_branch: revision)
}
)
在我的工作配置中,我检查了 Restrict where this project can be run
并给出了正确的从属标签。
我的作业因以下错误而失败:
ERROR: Failed to run DSL Script
java.io.IOException:
Cannot run program "/home/jenkins/workspace/my-flow-job/scripts/my_script.sh":
error=2, No such file or directory
我发现 DSL 脚本 运行ning 在主节点而不是从节点上。
我如何运行 从站上的 DSL? (或者至少在从机上执行脚本)
谢谢
您应该为当前频道创建一个文件路径并创建一个启动器来启动您的脚本。像下面这样的东西应该适合你。
def envVars = build.getEnvironment(listener)
def workspace = envVars.get("WORKSPACE")
def command = workspace+"""/scripts/my_script.sh"""
def channel = build.workspace.channel
def fp = build.workspace.toString()
def workspacePath = new hudson.FilePath(channel, fp)
def launcher = workspacePath.createLauncher(hudson.model.TaskListener.NULL);
def starter = launcher.launch().pwd(workspacePath).stdout(out).stderr(out).cmdAsSingleString(command)
starter.join()