如果同一Shell命令位于Jenkins管道的不同阶段,则其行为会有所不同 [英] The same shell command behaves differently if it is located in different stages of Jenkins pipeline

查看:71
本文介绍了如果同一Shell命令位于Jenkins管道的不同阶段,则其行为会有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Jenkins管道中执行以下步骤

I'm trying to execute following stage in Jenkins pipeline

        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:

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.

我注意到以下命令具有相同的行为(我的意思是Shell命令的不同行为取决于管线中的阶段位置):

I noticed the same behaviour (I mean different behaviour of shell command depending on stage position in pipeline) with following command:

sh "sed -i '/schedule_interval=/c\\ \\ \\ \\ schedule_interval=None,' ./volumes/dags/*.py"

如果此命令位于最后一级,则返回错误,例如"./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)

如果此命令位于Jenkins Pipeline的唯一阶段,则对./volumes/dags目录中的所有python文件执行sed命令

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

怎么可能?

推荐答案

在调查过程中,我意识到,尚未在部署期间创建文件. 通过添加解决了

During investigation I has realized, that during deploy files were not created yet. Was resolved by adding

sleep 15

sed或查找命令之前

before sed or find commands

这篇关于如果同一Shell命令位于Jenkins管道的不同阶段,则其行为会有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆