2015-11-01 90 views
1

我有一個Build Flow項目,它有一個DSL腳本來配置流程。在從屬服務器上運行jenkins 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腳本主節點,而不是從屬節點上運行。

如何在從屬設備上運行DSL? (或者至少在slave上執行腳本)

感謝

+0

您指的是哪種類型的「流量計劃」? [Build Flow](https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin)或[Workflow](https://wiki.jenkins-ci.org/display/JENKINS/Workflow+插入)? –

+0

@GeroldBroser - 我使用Build Flow –

+0

我不確定構建流程,但是,工作流程具有[使用奴隸的''節點'語句](https://github.com/jenkinsci/workflow-plugin/斑點/主/ TUTORIAL.md#使用從站)。 –

回答

1

你應該創建當前通道文件路徑,並創建一個啓動器來啓動你的腳本。像下面這樣的東西應該適合你。

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() 
相關問題