用 jenkins 启动 docker 容器后 workspace 咋找不到了?

在coding上尝试使用了一把持续集成功能,本想照着上面的模板用 docker 部署一下 node 环境给前端打包用。现在的问题是一进容器就找不到 workspace 请大家帮我看看我的jenkinsfile哪里有问题。

pipeline {
  agent any
  stages {
    stage('检出') {
      steps {
        checkout([
          $class: 'GitSCM', branches: [[name: env.GIT_BUILD_REF]],
          userRemoteConfigs: [[
            url: env.GIT_REPO_URL,
            credentialsId: env.CREDENTIALS_ID
          ]]
        ])
        sh '''ls -alh
echo "$PWD"'''
      }
    }
    stage('构建') {
      agent {
        docker {
          image 'node:10.19.0-alpine'
          args '-v "$PWD":/usr/src/app -w /usr/src/app'
        }

      }
      steps {
        echo '构建中...'
        sh '''node --version
pwd
ls -alh
cd /usr/src/app
ls -alh'''
        echo '构建完成.'
        script {
          def exists = fileExists 'README.md'
          if (!exists) {
            writeFile(file: 'README.md', text: 'Helloworld')
          }
        }

        archiveArtifacts(artifacts: 'README.md', fingerprint: true)
      }
    }
    stage('测试') {
      steps {
        echo '单元测试中...'
        echo '单元测试完成.'
        writeFile(file: 'TEST-demo.junit4.AppTest.xml', text: '''
                    <testsuite name="demo.junit4.AppTest" time="0.053" tests="3" errors="0" skipped="0" failures="0">
                        <properties>
                        </properties>
                        <testcase name="testApp" classname="demo.junit4.AppTest" time="0.003"/>
                        <testcase name="test1" classname="demo.junit4.AppTest" time="0"/>
                        <testcase name="test2" classname="demo.junit4.AppTest" time="0"/>
                    </testsuite>
                ''')
        junit '*.xml'
      }
    }
    stage('部署') {
      steps {
        echo '部署中...'
        echo '部署完成'
      }
    }
  }
}

第一次先在容器外面执行了一下 pwd 结果是 /root/workspace

然后启动容器时,执行第一次 pwd 结果是 /root/workspace@2 ,里面是空的,按道理说应该有我签出的代码呀。之后 cd 到我在 -w 参数中指定的 目录(按道理说应该进去的就是这个目录),打印了一下目录里的文件还是没有签出的代码。

讨论数量: 1
sanders

😓找到了,在 /usr/src/app/workspace 这里面。

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!