Jenkins不会通过sh'cd directory'命令更改目录

伊戈尔(Igor Vlasuyk)

我使用mac。我在react-native上有ios和android项目,并为每个项目创建了fastlane脚本。现在,我想在管道中自动使用Jenkins进行构建,因此我有Jenkins文件。在Jenkins的工作空间中,我必须转到ios文件夹并执行fastlane脚本。

但问题在于Jenkins不会使用command更改目录sh 'cd ios'我可以看到它,因为我pwd在更改目录命令之前和之后执行命令。

我尝试使用符号链接,在当前进程中使用“点”命令(例如sh '. cd ios'运行命令,并尝试使用ios文件夹的完整路径。但这一切并没有带来成功:(

那么,为什么詹金斯不使用sh 'cd ios'命令更改目录我该如何应对?先感谢您。

这是我的剧本

pipeline {

代理任何

工具{nodejs“ Jenkins_NodeJS”}

阶段{

stage('Pulling git repo'){
  steps{
    git(
      url: 'url_to_git_repo',
      credentialsId: 'jenkins_private_key2',
      branch: 'new_code'
    )
  }
}

stage('Prepare') {
    steps{
      sh 'npm install -g yarn'
      sh 'yarn install'
    }
}

stage('Building') {
    steps{
      sh 'cd /Users/igor/.jenkins/workspace/MobileAppsPipeline/ios'
      sh 'ls -l'
      sh '/usr/local/bin/fastlane build_and_push'
    }
}

}}

奥兹列夫卡

这是因为所有Jenkins命令都在目录[Jenkins home] / workspace / [您的管道名称]中运行(希望您使用管道)。

如果您需要更改目录,则脚本应类似于:

node {
    stage("Test") {
        sh script:'''
          #!/bin/bash
          echo "This is start $(pwd)"
          mkdir hello
          cd ./hello
          echo "This is $(pwd)"
        '''
    }
}

您的输出将是:

在此处输入图片说明

第二个sh命令将在工作空间目录中启动。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章