詹金斯共享同一个工作区

时间:2021-06-14 20:05:14

标签: git jenkins jenkins-pipeline

在尝试运行 jenkins 作业时,作业因错误而中断:

git clone https://XXXX%@github.com/XXX/XXX
fatal: destination path 'ns-test' already exists and is not an empty directory.

似乎每次运行共享相同的目录。

这是正确的吗?

我想知道 jenkins 的工作是孤立运行的..

我的脚本是:

pipeline {
agent { 
   docker { 
    image 'python:3.5.1' 
    args '-v=/etc/passwd:/etc/passwd'
    } 
}
stages {
    stage('checkout') {
        steps {
            sh 'git clone https://XXXX:XXXX%@github.com/XXXX/XXXX.git'
        }
    }
    stage('build') {
        steps {
            sh 'ls && pip install -r requirements.txt '
        }
    }
}

1 个答案:

答案 0 :(得分:0)

当您尝试在仍包含 .git 文件夹的文件夹中克隆存储库时,会出现此错误。
Git clone 从 github 复制文件并将它们放入一个文件夹中。如果您再次尝试这样做,它不会让您这样做,因为它无法克隆到已包含文件的文件夹中。
所以解决方案可能是:

  1. 在进行克隆之前删除文件夹。 sh 'rm -rf .git'
  2. 使用 git 插件: 更多信息:In Jenkins, how to checkout a project into a specific directory (using GIT)