Unable to get a variable value from last success build

125 views
Skip to first unread message

Rajesh M

unread,
Apr 12, 2020, 11:00:17 PM4/12/20
to Jenkins Users
Hi,

I am trying to get a variable value from last successful build, but getting error "groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.previousBuild() is applicable for argument types: () values: []".

void lastSuccessSVNRevision() {
   
def lastSuccessSVNRev = 0
   
def build = currentBuild.previousBuild()
   
while (build != null) {
       
if (build.result == "SUCCESS")
       
{
            lastSuccessSVNRev
= build.getRawBuild().actions.find{ it instanceof ParametersAction }?.parameters.find{it.name == 'SVN_REVISION'}?.value
           
break
       
}
        build
= build.previousBuild()
   
}
}

Could you someone help me to get the variable value from last success build.

Thanks,
Rajesh M

Devin Nusbaum

unread,
Apr 13, 2020, 10:36:19 AM4/13/20
to Jenkins Users
The problem is that you are using Groovy method call syntax, but the name of the method is `getPreviousBuild`, so you should use `currentBuild.getPreviousBuild()`. You could also use `currentBuild.previousBuild` with no parentheses, since Groovy has syntactic sugar for accessing getter methods using property syntax.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ae6d7cec-7b35-406f-9f26-dcad534a1eba%40googlegroups.com.

Rajesh M

unread,
Apr 13, 2020, 3:17:54 PM4/13/20
to Jenkins Users
Thanks Devin. I have tried these, but getting "No such property: lastSuccessSVNRev for class: Script2" error. I am new to groovy, so couldn't find why it is causing.


On Monday, 13 April 2020 16:36:19 UTC+2, Devin Nusbaum wrote:
The problem is that you are using Groovy method call syntax, but the name of the method is `getPreviousBuild`, so you should use `currentBuild.getPreviousBuild()`. You could also use `currentBuild.previousBuild` with no parentheses, since Groovy has syntactic sugar for accessing getter methods using property syntax.
On Apr 12, 2020, at 18:29, Rajesh M <rajesh...@gmail.com> wrote:

Hi,

I am trying to get a variable value from last successful build, but getting error "groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.previousBuild() is applicable for argument types: () values: []".

void lastSuccessSVNRevision() {
   
def lastSuccessSVNRev = 0
   
def build = currentBuild.previousBuild()
   
while (build != null) {
       
if (build.result == "SUCCESS")
       
{
            lastSuccessSVNRev
= build.getRawBuild().actions.find{ it instanceof ParametersAction }?.parameters.find{it.name == 'SVN_REVISION'}?.value
           
break
       
}
        build
= build.previousBuild()
   
}
}

Could you someone help me to get the variable value from last success build.

Thanks,
Rajesh M

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

On Monday, 13 April 2020 16:36:19 UTC+2, Devin Nusbaum wrote:
The problem is that you are using Groovy method call syntax, but the name of the method is `getPreviousBuild`, so you should use `currentBuild.getPreviousBuild()`. You could also use `currentBuild.previousBuild` with no parentheses, since Groovy has syntactic sugar for accessing getter methods using property syntax.
On Apr 12, 2020, at 18:29, Rajesh M <rajesh...@gmail.com> wrote:

Hi,

I am trying to get a variable value from last successful build, but getting error "groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.previousBuild() is applicable for argument types: () values: []".

void lastSuccessSVNRevision() {
   
def lastSuccessSVNRev = 0
   
def build = currentBuild.previousBuild()
   
while (build != null) {
       
if (build.result == "SUCCESS")
       
{
            lastSuccessSVNRev
= build.getRawBuild().actions.find{ it instanceof ParametersAction }?.parameters.find{it.name == 'SVN_REVISION'}?.value
           
break
       
}
        build
= build.previousBuild()
   
}
}

Could you someone help me to get the variable value from last success build.

Thanks,
Rajesh M

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages