I used example from this page to load groovy script from file to pipeline:
https:
//stackoverflow.com/questions/37800195/how-do-you-load-a-groovy-file-and-execute-it
My Script.groovy file (placed in %workspace% directory):
import testlink.api.java.client.TestLinkAPIClient;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;
def exampleMethod()
{
println("exampleMethod message");
def DEVKEY = "1f344123b456bd9dd822a7f824c194c3";
def URL = "http://TestLinkPC/lib/api/xmlrpc/v1/xmlrpc.php";
TestLinkAPIClient api = new TestLinkAPIClient(DEVKEY, URL);
}
def otherExampleMethod()
{
println("otherExampleMethod message");
}
return this
The significant part of my pipeline:
def rootDir = pwd()
println("Current Directory: " + rootDir)
def example = load "${rootDir}\\Script.groovy"
example.exampleMethod()
example.otherExampleMethod()
When in method "exampleMethod()" is only "println("exampleMethod")" all
works well
("exampleMethod message" and "otherExampleMethod message" is printed in
console log,
but when I add to "exampleMethod()":
def DEVKEY = "1f344123b456bd9dd822a7f824c194c3";
def URL= "http://TestLinkPC/lib/api/xmlrpc/v1/xmlrpc.php";
TestLinkAPIClient api = new TestLinkAPIClient(DEVKEY, URL);
my job finish with "FAILURE" result, without info about reason of error.
Maybe the main reason is that the TestLinkAPIClient class is created in
Java and not Groovy?
W dniu poniedziałek, 15 kwietnia 2019 12:42:29 UTC+2 użytkownik
kuisathaverat napisał:
>
> the problem is that you are not running the code as Groovy script, you
> include the code in your pipeline script, it is not the same.
>
> save this as a Groovy script in your repo, something like
> scripts/my-testlink.groovy
>
> #!/usr/bin/env groovy
> import testlink.api.java.client.TestLinkAPIResults.*
> import testlink.api.java.client.TestLinkAPIClient.*
>
> def DEVKEY = "1f123453b123bd8dd811a7f824c194d0"
> def URL = "http://PC4/lib/api/xmlrpc/v1/xmlrpc.php
> <http://pc4/lib/api/xmlrpc/v1/xmlrpc.php>"
> def api = new TestLinkAPIClient(DEVKEY, URL)
> TestLinkAPIResults projects = api.getProjects()
> api.createTestProject(...)
>
>
> then use it on your pipeline
>
> ```
> node(){
> sh(label: 'my script', script:'./scripts/my-testlink.groovy')
> }
> ```
>
> El lun., 15 abr. 2019 a las 11:39, Marogo Ytcutc (<[email protected]
> <javascript:>>) escribió:
>
>> Still doesn't work. :-( I will describe what I have done in turn.
>> I downloaded the file "testlink-api-client-2.0.zip" from:
>>
>> https://code.google.com/archive/p/dbfacade-testlink-rpc-api/downloads
>>
>> After extract archive I placed the file "testlink-api-client-2.0.jar" in
>> directory "D:\Jenkins\testlink\"
>>
>> In the configuration of my job in Jenkins I marked the option "Prepare an
>> environment for the run"
>> and set "Properties Content" to:
>>
>> CLASSPATH=D:\\Jenkins\\testlink
>>
>> My pipeline code in Jenkins job:
>>
>> #!/usr/bin/env groovy
>> import groovy.json.JsonSlurper
>> import testlink.api.java.client.TestLinkAPIResults.*
>> import testlink.api.java.client.TestLinkAPIClient.*
>>
>> node('PC-2')
>> {
>> ansiColor('xterm')
>> {
>> try
>> {
>> echo "CLASSPATH: " + env.CLASSPATH
>> def DEVKEY = "1f344123b456bd9dd822a7f824c194c3"
>> def URL= "http://TestLinkPC/lib/api/xmlrpc/v1/xmlrpc.php"
>> def api = new TestLinkAPIClient(DEVKEY, URL)
>> }
>> catch(e)
>> {
>> String error = "${e}";
>> currentBuild.result = 'FAILURE'
>> emailext body: "Log: ${env.BUILD_URL}console", recipientProviders:
>> [[$class: 'FirstFailingBuildSuspectsRecipientProvider'], [$class:
>> 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider'], [
>> $class: 'UpstreamComitterRecipientProvider']], subject: "Build
>> #${env.BUILD_NUMBER} of job ${env.JOB_NAME} finished with status:
>> ${currentBuild.currentResult}"
>> }
>> }
>> }
>>
>> In console log I received an error:
>>
>> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
>> failed:
>> WorkflowScript: 22: unable to resolve class TestLinkAPIClient
>> @ line 22, column 18.
>> def api = new TestLinkAPIClient(DEVKEY, URL)
>> ^
>>
>> Where is the problem?
>>
>>
>>
>> W dniu sobota, 13 kwietnia 2019 23:38:38 UTC+2 użytkownik Marogo Ytcutc
>> napisał:
>>>
>>> Thank You very much for Your help! I will check it on Monday.
>>>
>>> W dniu sobota, 13 kwietnia 2019 21:09:40 UTC+2 użytkownik Ivan Fernandez
>>> Calvo napisał:
>>>>
>>>> Put the jar file in a folder inside the classpath of the JDK used by
>>>> your agent
>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Jenkins Users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/jenkinsci-users/70qz8g46LpQ/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/jenkinsci-users/9f8c7cc0-66e5-4411-89e2-c384158d0131%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/jenkinsci-users/9f8c7cc0-66e5-4411-89e2-c384158d0131%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Un Saludo
> Iván Fernández Calvo
> https://www.linkedin.com/in/iv%C3%A1n-fern%C3%A1ndez-calvo-21425033
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/9869ac83-207d-4f1e-b628-34ca71c29eee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.