git 尝试按照Jenkins管道构建时出现cd目录错误

1dkrff03  于 2023-05-05  发布在  Git
关注(0)|答案(1)|浏览(210)

Jenkins管道脚本未运行。我能知道这个Jenkins管道脚本的原因吗?

pipeline {   
    agent any           
    stages{   
        stage('Git checkout'){   
            steps{   
                script{
                  git branch: 'development', credentialsId: '...elided...'
                }
            }
        }
        stage('gradle build'){   
            steps{   
                script{   
                    sh """
                     cd cws/ReportRepo/th.cws/thub/mod.cwscommon
                     ./gradle clean build
                     ./gradle publishToMavenLocal
                    """
                }
            }
        }
        stage('second file gradle build'){   
            steps{   
                script{   
                    sh """
                     cd cws/ReportRepo/th.cws/thub/mod.cwsaudit
                     ./gradle clean build
                     ./gradle publishToMavenLocal
                    """
                }
            }
        }
        stage('third file gradle build'){   
            steps{   
                script{                       
                    sh """
                     cd cws/ReportRepo/th.cws/thub/mod.cwscore
                     ./gradle clean build
                     ./gradle publishToMavenLocal
                    """   
                }
            }
        }
        stage('fourth file gradle build'){   
            steps{   
                script{                       
                    sh """
                     cd cws/ReportRepo/th.cws
                     ./gradle clean build
                     ./gradle publishToMavenLocal
                    """
                }
            }
        }
        stage('file gradle build'){
            steps{
                script{
                    sh """
                     cd cws-batch-api-ms
                     ./gradle clean build
                     cd cws-batch-api-ms/build/l
                     docker buildx build --platform linux/amd64 -t cws-backend .
                   """
                }
            }
        }
     }
 }

这个错误我得到cd: directory permission denied

+ cd cws/ReportRepo/th.cws/thub/mod.cwscommon
/var/lib/jenkins/workspace/mcn@2@tmp/durable-b82db53a/script.sh: 2: cd: can't cd to cws/ReportRepo/th.cws/thub/mod.cwscommon
v8wbuo2f

v8wbuo2f1#

如果您在特定目录中运行命令,最好使用Jenkins中的dir命令,而不是使用sh脚本中的cd

script{
  dir("cws/ReportRepo/th.cws/thub/mod.cwscommon") {
    sh """
       ./gradle clean build
       ./gradle publishToMavenLocal
    """
  }
}

由于您收到权限拒绝错误,可能您的Jenkins用户没有访问cws文件夹的必要权限?尝试以Jenkins用户身份手动登录并访问文件夹,看看是否可行。如果没有,您可以向用户给予读取权限。

相关问题