带有Windows Docker容器的Jenkins共享库

时间:2019-01-10 22:48:19

标签: windows docker jenkins shared-libraries jenkins-pipeline

目标:
在Windows Jenkins节点上,我想在Windows docker容器内克隆GitHub项目,并使用Jenkinsfile运行maven命令。

问题:
由于无效的卷规格,我无法在Jenkins中启动Docker容器。有谁知道解决方法或如何解决此问题?

详细信息:
目前,我有一个声明式管道,其轮廓如下:

TestBed

在Jenkins中,它生成以下命令:

foreach (glob("your_template_path/*/*/*.twig") as $filename) {

    $content = file_get_contents($filename);

    $content = preg_replace_callback('/{% trans "[\s\S]+?" %}/',function($matches) {
        $text = str_replace(['{% trans','%}','"'],'',$matches[0]);
        return '{% trans %}'.trim($text).'{% endtrans %}';
    },$content);
    $content = preg_replace_callback('/{% trans \'[\s\S]+?\' %}/',function($matches) {
        $text = str_replace(['{% trans','%}',"'"],'',$matches[0]);
        return '{% trans %}'.trim($text).'{% endtrans %}';
    },$content);

    file_put_contents($filename,$content);

}

错误:

/**
 * Defines declarative pipelne for a standard maven build.
 */
def call(body) {
  def config = [:]
  body.resolveStrategy = Closure.DELEGATE_FIRST
  body.delegate = config
  body()

  pipeline {
    agent {
      label "WINDOWS-64-DOCKER"
    }

    stages {
      stage('Maven') {
        agent {
          docker {
            image 'enterprise-repos.net/my-org/windows-maven3-jdk7'
            reuseNode true
          }
        }

        steps {
          script {
            def script = "mvn clean install"
            sh returnStdout: false, script: script
          }
        }
      }
    }
  }
}

Windows Jenkins节点的路径环境变量:

Windows_Docker does not seem to be running inside a container
$ docker run -t -d -u 18:18 -w c:\jenkins\workspace\git_hub_project 
-v c:\jenkins\workspace\git_hub_project:c:\jenkins\workspace\git_hub_project:rw,z 
-v c:\jenkins\workspace\git_hub_project@tmp:c:\jenkins\workspace\git_hub_project@tmp:rw,z 
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 
-e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 
enterprise-repos.net/my-org/windows-maven3-jdk7 cat

Docker版本:

java.io.IOException: Failed to run image 'enterprise-repos.net/my-org/windows-maven3-jdk7'. Error: docker: 
Error response from daemon: invalid volume specification: 'c:\jenkins\workspace\git_hub_project:c:\jenkins\workspace\git_hub_project:rw,z'.
See 'docker run --help'.

推测:根据我目前的理解,我不确定docker命令是如何生成的,但是我认为我的问题是C:\Program Files\java\jre1.8.0_172\bin; C:\Windows\Sun\Java\bin; C:\Windows\system32; C:\Windows; C:\Program Files (x86)\Common Files\Oracle\Java\javapath; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Windows\System32\OpenSSH\; C:\Program Files\Docker; C:\ProgramData\chocolatey\bin; C:\Program Files\Git\cmd; C:\Users\jenkins\AppData\Local\Microsoft\WindowsApps; C:\Program Files\Git\mingw64\bin; C:\Program Files\Git\usr\bin; C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps; . 之后的Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.3 Git commit: 33a45cd0a2 Built: unknown-buildtime OS/Arch: windows/amd64 Experimental: false Server: Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.24) Go version: go1.10.3 Git commit: 33a45cd0a2 Built: 11/07/2018 00:24:12 OS/Arch: windows/amd64 Experimental: false 标志因为Jenkins节点是Windows,而Docker映像也是Windows。任何帮助或建议都会很可爱。

0 个答案:

没有答案