0

我正在尝试使用 jenkinsfile 构建一个简单的 jenkins docker 管道。

我遇到的问题是我想在将图像推送到存储库之前对其进行测试,但我不知道如何在阶段或步骤之间保留引用。我尝试在顶部添加 def app = null, 但它仍然给出相同的错误。

def app = null
pipeline {
  agent {
    node {
      label 'master'
    }

  }
  stages {
    stage('Clone repository') {
      steps {
        checkout scm
      }
    }
    stage('Build image') {
      steps {
        script {
            app = docker.build("socketserver")
        }
      }
    }
    stage('Test image') {
      steps {
        script {
          app.inside { 
            sh 'echo "Tests passed"'
          }
        }

      }
    }
    stage('Push image') {
      steps {
        script {
          docker.withRegistry('http://localhost:5000') {
            app.push("${env.BUILD_NUMBER}")
            app.push("latest")
          }
        }
      }
    }
  }
}

这是错误日志。与全局变量相关的主要错误:groovy.lang.MissingPropertyException:没有这样的属性:类的应用程序:groovy.lang.Binding

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/socketserver_master-
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://bitbucket.org//socketserver.git # timeout=10
Cleaning workspace
 > git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > git reset --hard # timeout=10
 > git clean -fdx # timeout=10
Fetching without tags
Fetching upstream changes from https://bitbucket.org//socketserver.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials Bitbucket server credentials
 > git fetch --no-tags --progress https://bitbucket.org//socketserver.git +refs/heads/master:refs/remotes/origin/master
Checking out Revision (master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master
Commit message: "Merge remote-tracking branch 'origin/master'"
 > git rev-list --no-walk # timeout=10
Cleaning workspace
 > git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > git reset --hard # timeout=10
 > git clean -fdx # timeout=10
[Bitbucket] Notifying commit build result
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Clone repository)
[Pipeline] checkout
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://bitbucket.org//socketserver.git # timeout=10
Cleaning workspace
 > git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > git reset --hard # timeout=10
 > git clean -fdx # timeout=10
Fetching without tags
Fetching upstream changes from https://bitbucket.org//socketserver.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials Bitbucket server credentials
 > git fetch --no-tags --progress https://bitbucket.org//socketserver.git +refs/heads/master:refs/remotes/origin/master
Checking out Revision (master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master
Commit message: "Merge remote-tracking branch 'origin/master'"
Cleaning workspace
 > git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > git reset --hard # timeout=10
 > git clean -fdx # timeout=10
[Bitbucket] Notifying commit build result
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build image)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
[socketserver_master-] Running shell script
+ docker build -t socketserver .
Sending build context to Docker daemon  264.7kB

Step 1/13 : FROM node:alpine
 ---> 166e2eca249b
Step 2/13 : WORKDIR /usr/src/backend
 ---> Using cache
 ---> 56dc436a7e34
Step 3/13 : RUN chown node ./
 ---> Using cache
 ---> b071d6e3a903
Step 4/13 : USER node
 ---> Using cache
 ---> 8460f06b3a1d
Step 5/13 : COPY package.json ./
 ---> Using cache
 ---> c92329f78eba
Step 6/13 : RUN npm install
 ---> Using cache
 ---> 6446d98bec57
Step 7/13 : COPY tsconfig.json ./
 ---> Using cache
 ---> 9bff04748ec1
Step 8/13 : COPY tslint.json ./
 ---> Using cache
 ---> 299b102a7976
Step 9/13 : COPY tspaths.js ./
 ---> Using cache
 ---> d388af7ce02a
Step 10/13 : COPY app ./app
 ---> Using cache
 ---> 917fd4b2bfba
Step 11/13 : ENV STATICPORT=3000
 ---> Using cache
 ---> 2caee18034cb
Step 12/13 : ENV WSPORT=8080
 ---> Using cache
 ---> b02bf3a45e8c
Step 13/13 : CMD [ "npm", "start" ]
 ---> Using cache
 ---> 89e5ade6d29e
Successfully built 89e5ade6d29e
Successfully tagged socketserver:latest
[Pipeline] dockerFingerprintFrom
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test image)
[Pipeline] script
[Pipeline] {
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Push image)
Stage "Push image" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
groovy.lang.MissingPropertyException: No such property: app for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
    at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at WorkflowScript.run(WorkflowScript:25)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
    at sun.reflect.GeneratedMethodAccessor169.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
4

0 回答 0