[英]The same shell command behaves differently if it is located in different stages of Jenkins pipeline
I'm trying to execute following stage in Jenkins pipeline我正在尝试在 Jenkins 管道中执行以下阶段
stage('RUN') {
steps{
dir("airflow-dags") {
sh "find ./volumes/dags/ -maxdepth 1 -name '*.py' -print0"
}
}
}
If this stage is located in the last position (after deploy and other stuff) it returns nothing:如果这个阶段位于最后一个 position (在部署和其他东西之后)它什么都不返回:
08:56:58 Running in /home/jenkins/workspace/QA_deploy_Docker/airflow-dags
[Pipeline] {
[Pipeline] sh
08:56:59 + find ./volumes/dags/ -maxdepth 1 -name '*.py' -print0
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
If I remove all stages before this stage and leave only this one in pipeline, it returns correct output with list of files.如果我删除此阶段之前的所有阶段并仅将这一阶段留在管道中,它将返回正确的 output 和文件列表。
I noticed the same behaviour (I mean different behaviour of shell command depending on stage position in pipeline) with following command:我注意到相同的行为(我的意思是 shell 命令的不同行为,具体取决于管道中的阶段 position)使用以下命令:
sh "sed -i '/schedule_interval=/c\\ \\ \\ \\ schedule_interval=None,' ./volumes/dags/*.py"
If this command is located in the last stage it returns error, like "./volumes/dags/*.py" no such file (it quote the path)如果此命令位于最后阶段,则返回错误,例如“./volumes/dags/*.py”没有此类文件(它引用路径)
Whereas if this command is located in the only stage of Jenkins Pipeline, then sed command executed agaainst all python files of./volumes/dags directory if it而如果此命令位于 Jenkins Pipeline 的唯一阶段,则针对 ./volumes/dags 目录的所有 python 文件执行 sed 命令
How it can be?怎么可能?
During investigation I has realized, that during deploy files were not created yet.在调查期间,我意识到,在部署期间尚未创建文件。 Was resolved by adding
已通过添加解决
sleep 15
before sed or find commands sed 之前或查找命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.