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

282 views Asked by At

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

There are 1 answers

0
Valery Fludkov On

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

sleep 15

before sed or find commands