【问题标题】:how to configure multiple shell scripts on Jenkins and run them without waiting for the other script如何在 Jenkins 上配置多个 shell 脚本并在不等待其他脚本的情况下运行它们
【发布时间】:2016-03-07 06:16:33
【问题描述】:

我正在尝试从 jenkins 运行一个 shell 脚本,格式如下

ssh host1 'nohup path/script.sh &'

ssh host2 'nohup path/script.sh &'

ssh host3 'nohup path/script.sh &'

sleep 90

ssh host1 'nohup path/script.sh &'

ssh host2 'nohup path/script.sh &'

ssh host3 'nohup path/script.sh &'

我想同时并行运行前三个脚本,然后休眠一段时间并开始处理接下来的三个脚本,最后以相同的顺序打印所有 6 个脚本的输出到 jenkins 构建日志。我正在使用 nohup 让脚本在后台运行,并且不想将脚本的日志输出到任何文件。不想用nohup script.sh >dev/null

【问题讨论】:

    标签: linux bash shell jenkins ssh


    【解决方案1】:

    首先,ssh 进程应该在后台运行,而不是远程进程。其次,使用 wait 内置而不是 sleep (这是相当不稳定的)。

    # Create temporary files for the commmand's output
    output1=$(mktemp)
    output2=$(mktemp)
    output3=$(mktemp)
    
    > "$output1" ssh host1 'path/script.sh' &
    > "$output2" ssh host2 'path/script.sh' &
    > "$output3" ssh host3 'path/startNode.sh' &
    wait && cat "$output1" "$output2" "$output3"
    
    # Cleanup tempfiles
    rm  "$output1" "$output2" "$output3"
    
    ... more stuff
    

    我正在为每个命令的输出使用临时文件。完成所有作业后,将连接并打印输出。

    【讨论】:

    • 我需要为每个shell脚本打印输出。通过执行上述操作..作业运行..但每个shell的输出不会打印在作业/日志上
    • 作业完成后应该显示日志?
    • 3个不同脚本的日志混在一起,想把它们分开
    • 我试过上面的脚本。脚本失败。我有 output1=$(temp1) output2=$(tempfile) .. 它在第 2 行寻找 temp1 文件时失败,说第 2 行找不到 temp1
    • output1=$(tempfile) output2=$(tempfile) output3=$(tempfile) 它在第 2 行失败。
    猜你喜欢
    • 2022-08-26
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 2019-02-02
    • 2016-05-27
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多