首页 文章

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

提问于
浏览
0

我有一个用于构建我的Android应用程序的管道 . 在某些阶段,我有shell脚本 . 当我一个接一个地运行各个阶段(通过评论其他人)时,一切正常,但当我一起运行它们时,我看到了奇怪的行为 .

似乎shell脚本在 parallel 中运行!!

这是我的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()}/
                """
          }
        }
    }

}

我只想运行步骤同步(当然还有shell脚本),我的问题是什么?

这是我看到的:

在“清理”步骤中,文件夹将被删除,并且模板文件夹的新副本将被复制到工作目录 . 步骤“拉动本地回购”和“拉电晕回购”做他们应该做的工作 . 但在步骤“构建”中,我可以看到“native-corona-android”文件的一部分消失,“gradlew”脚本被删除 . 我也看到了整个“native-corona-android”文件夹被删除的情况 . 然后我想再次调用“清理”步骤中的脚本 .

谢谢

1 回答

  • 0

    除非您使用 parallel 指令,否则所有步骤都应该同步运行 .

    你观察到什么行为?哪些步骤并行运行?

相关问题