简体   繁体   English

Jenkins管道中的shell脚本是否异步运行?

[英]Does shell scripts in Jenkins pipeline run asynchronously?

I have a pipeline for building my android application. 我有一个构建我的android应用程序的管道。 In some stages, I have shell scripts. 在某些阶段,我有shell脚本。 when I run the stages one by one(by commenting others) everything works fine, but when I run them all together I see strange behavior. 当我一个个运行一个阶段(通过评论其他阶段)时,一切正常,但是当我一起运行它们时,我会看到奇怪的行为。

It seems that the shell scripts are running in parallel !! 看来shell脚本正在并行运行!

here is my jenkinsfile : 这是我的jenkinsfile:

pipeline{
    agent any

    stages{
        stage("Clean"){
          agent{
            node{
              label 'master'
              customWorkspace getMainDirectory()
            }
          }
          steps{
              sh """#!/bin/bash
                rm -rf Corona
                rm -rf native-corona-android
                cd ..
                cp -a TemplateWorkspace/. ${getCoronaBranch()}-${getNativeBrach()}
                """
          }
        }
        stage("pull native repo"){
            agent{
              node{
                label 'master'
                customWorkspace getNativeProjectPath()
              }
            }
            steps{
                echo "pulling native"
                git(
                   url: nativeRepositoryAddress,
                   credentialsId: credentialsId,
                   branch: getNativeBrach()
                )
                echo "pulling done"
            }
        }
        stage("pull corona repo"){
            agent{
              node{
                label 'master'
                customWorkspace getCoronaProjectPath()
              }
            }
            steps{
                echo "pulling corona"
                git(
                   url: coronaRepositoryAddress,
                   credentialsId: credentialsId,
                   branch: getCoronaBranch()
                )
                echo "pulling done"
            }
        }
        stage("build"){
            environment {
                docDir = getMainDirectory()
                ANDROID_HOME = getAndroidSDKLocation()
            }
            agent{
              node{
                label 'master'
                customWorkspace getNativeProjectPath()
              }
            }
            steps{
                sh """#!/bin/bash
                ./gradlew clean
                ./gradlew changeFiles --stacktrace --no-daemon
                ./gradlew assembleDebug --stacktrace --no-daemon
                """
            }
        }
        stage("move build files"){
          agent{
            node{
              label 'master'
              customWorkspace getGradleBuildLocation()
            }
          }
          steps{
              sh """#!/bin/bash
                yes | cp -rf * ../../../../JenkinsBuilds/${getOutputFolder()}/
                """
          }
        }
    }

}

I just want to run steps synchronous(and of course shell scripts), What is my problem? 我只想同步运行步骤(当然还有shell脚本),我的问题是什么?

Here is what I see: 这是我看到的:

In "Clean" step the folders get deleted and a fresh copy of Template folders get copied to work directory. 在“清理”步骤中,将删除文件夹,并将模板文件夹的新副本复制到工作目录。 Steps "pull native repo" and "pull corona repo" do the jobs they should do. 步骤“拉本地回购”和“拉电晕回购”执行其应做的工作。 but in step "build" I can see that a part of "native-corona-android" files is gone and "gradlew" script is deleted. 但是在“构建”步骤中,我可以看到“ native-corona-android”文件的一部分消失了,“ gradlew”脚本被删除了。 I have also seen situations where the whole "native-corona-android" folder gets deleted. 我还看到了整个“ native-corona-android”文件夹被删除的情况。 Then I thought that the script in "Clean" step is called again. 然后我想再次调用“清理”步骤中的脚本。

Thanks 谢谢

Unless you are using parallel directive all steps should be running synchronously. 除非使用parallel指令,否则所有步骤应同步运行。

What behavior do you observe? 您观察到什么行为? Which steps are running parallel? 哪些步骤并行运行?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM