Jenkins管道groovy.lang.MissingPropertyException [英] Jenkins pipeline groovy.lang.MissingPropertyException

查看:1525
本文介绍了Jenkins管道groovy.lang.MissingPropertyException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的groovy脚本,我正在使用Jenkins管道,并且在 git merge 操作上出现了一些奇怪的异常:

脚本:

  node(master){
ws(env.BUILD_NUMBER.toString()){ //工作区
withCredentials([
[$ class:'UsernamePasswordBinding',credentialsId:'bitbucket',变量:'BITBUCKET_AUTH'],
[$ class:'UsernamePasswordBinding',credentialsId:' bitbucket-https',变量:'BITBUCKET_HTTPS_AUTH'],]){

def applicationName = env.CUSTOMER_NAME
def packageName =no.bstcm.loyaltyapp。$ {env.REPO_NAME}
def googleServicesJsonContents = env.GOOGLE_SERVICES_JSON
bitbucketRepoName =android_loyalty_app _ $ {env.REPO_NAME}
def bitbucketRepoApiUrl =https://api.bitbucket.org/2.0/repositories/boost-开发/ $ {bitbucketRepoName}
def starterBranch =shoppi ng_mall
def projectPath =jenkins-project

stage('在bitbucket上创建存储库'){
shcurl POST -v -u $ BITBUCKET_AUTH $ bitbucketRepoApiUrl -H 'Content-Type:application / json'-d'{\is_private \:true,\project \:{\key \:\LOY \}}'


stage('Create local repository'){
dir(projectPath){
shgit init
shtouch README。 md
shgit add README.md
shgit commit --message ='Initial commit'
}
}

stage ('Merge starter'){
dir(projectPath){
shgit init
shgit remote add starter https://$BITBUCKET_HTTPS_AUTH@bitbucket.org/boost-development/ app_designer_starter_android.git
shgit fetch starter
shgit checkout master< --- FAILS HERE
shgit remote add origin https://$BITBUCKET_HTTPS_AUTH@bitbucket.org/boost-development/$bitbucketRepoName.git
shgit推-u原产主
shgit远程删除启动器
}
}
}
}
pre>

而我收到的异常(和管道破碎):

 <$ c $运行shell脚本
+ git fetch starter
从https://bitbucket.org/***/***
* [新分会]主人 - > starter / master
[管道] sh
[jenkins-project]正在运行的shell脚本
+ git checkout master
已经在'master'上
分支主设置为跟踪远程分支主从起动器。
[Pipeline]}
[Pipeline] // dir
[Pipeline]}
[Pipeline] // stage
[Pipeline]}
[Pipeline ] // withCredentials
[Pipeline]}
[Pipeline] // ws
[Pipeline]}
[Pipeline] //节点
[Pipeline]流水线结束
groovy.lang.MissingPropertyException:没有这样的属性:git for
class:org.codehaus.groovy.runtime.GStringImpl
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAd
apter.java:53)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
at org.kohsuke.groovy.sandbox.impl.Checker $ 4。在org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:52)上调用(Checker.java:243)
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor中的
。 onGetProperty(SandboxInterceptor.java:308)
at org.kohsuke.groovy.sandbox.impl.Checker $ 4.call(Checker.java:241)
at org.kohsuke.groovy.sandbox.impl.Checker .checkedGetPro perty(Checker.java:238)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock。 rawGet(PropertyAccessBlock.java:20)
at WorkflowScript.run(WorkflowScript:36)
at ___ cps.transform ___(Native Method)

你们有什么想法可能会导致这个问题?我不知道,谷歌在这里没有什么帮助。

解决方案

这种groovy字符串的麻烦:

  sh.... $ bitbucketRepoName.git ....

在这种情况下,groovy会尝试访问变量 bitbucketRepoName
$ b的属性 git $ b

只是改变它:

  sh.... $ {bitbucketRepoName} .git .... 


I have simple groovy script that I'm using with Jenkins pipeline and fails on the git merge operation with kind of strange exception:

The script:

node("master") {
ws(env.BUILD_NUMBER.toString()) { // workspace
    withCredentials([
        [$class: 'UsernamePasswordBinding', credentialsId: 'bitbucket', variable: 'BITBUCKET_AUTH'],
        [$class: 'UsernamePasswordBinding', credentialsId: 'bitbucket-https', variable: 'BITBUCKET_HTTPS_AUTH'],]) {

        def applicationName = env.CUSTOMER_NAME
        def packageName = "no.bstcm.loyaltyapp.${env.REPO_NAME}"
        def googleServicesJsonContents = env.GOOGLE_SERVICES_JSON
        def bitbucketRepoName = "android_loyalty_app_${env.REPO_NAME}"
        def bitbucketRepoApiUrl = "https://api.bitbucket.org/2.0/repositories/boost-development/${bitbucketRepoName}"
        def starterBranch = "shopping_mall"
        def projectPath = "jenkins-project"

        stage('Create repository on bitbucket') {
            sh "curl POST -v -u $BITBUCKET_AUTH $bitbucketRepoApiUrl -H 'Content-Type: application/json' -d '{\"is_private\": true, \"project\": {\"key\": \"LOY\"}}'"
        }

        stage('Create local repository') {
            dir(projectPath) {
                sh "git init"
                sh "touch README.md"
                sh "git add README.md"
                sh "git commit --message='Initial commit'"
            }
        }

        stage('Merge starter') {
            dir(projectPath) {
                sh "git init"
                sh "git remote add starter https://$BITBUCKET_HTTPS_AUTH@bitbucket.org/boost-development/app_designer_starter_android.git"
                sh "git fetch starter"
                sh "git checkout master" <--- FAILS HERE
                sh "git remote add origin https://$BITBUCKET_HTTPS_AUTH@bitbucket.org/boost-development/$bitbucketRepoName.git"
                sh "git push -u origin master"
                sh "git remote remove starter"
            }
        }
    }
}

And the exception I receive (and the pipeline broke):

[Pipeline] sh
[jenkins-project] Running shell script
+ git fetch starter
From https://bitbucket.org/***/***
 * [new branch]      master     -> starter/master
[Pipeline] sh
[jenkins-project] Running shell script
+ git checkout master
Already on 'master'
Branch master set up to track remote branch master from starter.
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // ws
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: git for 
class: org.codehaus.groovy.runtime.GStringImpl
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAd
apter.java:53)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:243)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:52)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:308)
at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at WorkflowScript.run(WorkflowScript:36)
at ___cps.transform___(Native Method)

Do you guys have any idea what could cause this problem? I have no idea and google doesn't help much here.

解决方案

trouble in this kind of groovy string:

sh ".... $bitbucketRepoName.git ...."

in this case groovy it tries to access property git of variable bitbucketRepoName

just change it this:

sh ".... ${bitbucketRepoName}.git ...."

这篇关于Jenkins管道groovy.lang.MissingPropertyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆