【发布时间】:2020-07-24 04:45:23
【问题描述】:
我想通过延迟每 5 秒在 Jenkins 上运行一个 shell 命令。以下是命令:
cd /cygdrive/c/path/project_name
./scheduler.sh &
在scheduler.sh 中是:
#!/bin/sh
sleep="/bin/sleep"
(sleep 5 && ./to_run.sh) &
(sleep 10 && ./to_run.sh) &
(sleep 15 && ./to_run.sh) &
(sleep 20 && ./to_run.sh) &
(sleep 25 && ./to_run.sh) &
(sleep 30 && ./to_run.sh) &
(sleep 35 && ./to_run.sh) &
(sleep 40 && ./to_run.sh) &
(sleep 45 && ./to_run.sh) &
(sleep 50 && ./to_run.sh) &
(sleep 55 && ./to_run.sh) &
(sleep 60 && ./to_run.sh) &
它将每 5 秒运行一次to_run.sh。 to_run.sh 包含运行 python 项目的脚本:
#!/bin/bash
PATH="$PATH;$PYTHON_PATH"
/cygdrive/c/path/venv/Scripts/activate & cd /cygdrive/c/path/project_name& python whatever.py runserver
echo "SUCCESS RUN ALL PYTHON SCRIPTS!"
但是,即使构建成功,我也会从 Jenkins 那里收到此错误:
Started by timer
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Oncore temp table
$ C:\cygwin64\bin\cygpath -w C:\cygwin64\bin\sh
[Oncore temp table] $ C:\cygwin64\bin\sh.exe -xe C:\WINDOWS\TEMP\jenkins4700784491498255011.sh
+ cd /cygdrive/c/path/project_name
+ ./scheduler.sh
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
./scheduler.sh: line 3: sleep: command not found
Finished: SUCCESS
我已经在 Jenkins 上设置了 cygwin:
请帮忙!
【问题讨论】:
-
您的 PATH 似乎不包括 /usr/bin。要么修复此问题 (
PATH=/usr/bin:$PATH),要么通过/usr/bin/sleep显式调用sleep。顺便说一句,您还分配了一个名为sleep的 shell 变量,您从不使用它。这是故意的吗? -
@user1934428 我在回答中提到了未使用的
$sleepshell 变量。