代码之家  ›  专栏  ›  技术社区  ›  mornindew

Jenkins文件图像标记参数不工作

  •  0
  • mornindew  · 技术社区  · 6 年前

    我正试图通过我的詹金斯管道自动标记我的图像,但它没有如我所期望的那样工作。我不擅长管道,我可能缺少一些基本的东西,但任何帮助都会得到感激。

    我希望使用内置的 {env.BUILD_NUMBER} 詹金斯提供的变量。我可以回显构建号,但不能将其传递到“imagebuilder”命令中。

    错误:

    [redFalconMonolith_RedFalcon-ZN46VHZ6UQAAXE632CFKUEXEBHIA52MJYXHIH6VUHK3MOAOQB64A] Running shell script
    + echo Build number: 108
    Build number: 108
    [Pipeline] sh
    [redFalconMonolith_RedFalcon-ZN46VHZ6UQAAXE632CFKUEXEBHIA52MJYXHIH6VUHK3MOAOQB64A] Running shell script
    + echo Image Tag: gcr.io/redfalcon-186521/redfalcon-webserver-minimal:RedFalcon.108
    Image Tag: gcr.io/redfalcon-186521/redfalcon-webserver-minimal:RedFalcon.108
    
    groovy.lang.MissingPropertyException: No such property: KEY 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:46)
        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.GeneratedMethodAccessor411.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
    

    代码:

    def project = 'redfalcon-186521'
    def  appName = 'redfalcon-webserver-minimal'
    ...
    
    stage('Build Container') {
                steps {
                    container('redfalcon-golang') {
                        sh "echo Build number: ${env.BUILD_NUMBER}"
                        sh "echo Image Tag: gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"
                        sh "imagebuilder -t gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER} --build-arg GITHUB_OATH_KEY=$KEY -f DockerFiles/Dockerfile.local ."
                    }
                }
            }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   mornindew    6 年前

    因为我完全不理解这个问题的原因是我的“key”属性(用于GitHub的OAuth密钥)在构建时没有正确地注入到Jenkins从系统中。它在我的dockerfile中,当我在本地运行它时,它就存在了,所以我不知道为什么詹金斯无法阅读它。

    我提出的解决方案是在系统设置中使用Jenkins环境变量,它工作得很好。

    我希望我知道为什么看不到它,但我没有时间来诊断它,因为Jenkins环境变量不能满足我的需要(而且不是一个重大的妥协)。