The same shell command behaves differently if it is located in different stages of Jenkins pipeline

浪子不回头ぞ 提交于 2021-01-07 06:37:14

问题


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.

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"

If this command is located in the last stage it returns error, like "./volumes/dags/*.py" no such file (it quote the path)

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

How it can be?


回答1:


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

sleep 15

before sed or find commands



来源:https://stackoverflow.com/questions/65016885/the-same-shell-command-behaves-differently-if-it-is-located-in-different-stages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!