Re: Jenkins - link a java package to pipeline

2019-04-15 Thread Ivan Fernandez Calvo
I've suggested you run a Groovy script on your agent using the Groovy CLI, 
not to include your groovy code in your pipeline, if you make a load it is 
the same that put the code in the Jenkinsfile (more or less),  

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/4688ec7e-acaf-43b5-a265-0ed587813dc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins - link a java package to pipeline

2019-04-15 Thread Marogo Ytcutc
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 
> "
>  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 ( >) 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 
>> 

Re: Jenkins - link a java package to pipeline

2019-04-15 Thread kuisathaverat
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
"
 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 ()
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
> jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/9f8c7cc0-66e5-4411-89e2-c384158d0131%40googlegroups.com
> 
> .
> 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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAKo5Qrq8U%2B6Xfso47S6nh3syaUxm9g_Jyza2xDEN5pYohzE_iQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins - link a java package to pipeline

2019-04-15 Thread Marogo Ytcutc
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 the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/9f8c7cc0-66e5-4411-89e2-c384158d0131%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins - link a java package to pipeline

2019-04-13 Thread Marogo Ytcutc
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 the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/9aeca568-9f1b-48f4-a7c5-fc640bb44241%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins - link a java package to pipeline

2019-04-13 Thread Ivan Fernandez Calvo
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 the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/2e82ec5e-da15-45eb-b6ea-fcf4788e406f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins - link a java package to pipeline

2019-04-12 Thread Marogo Ytcutc

The main problem is that Jenkins does not recognize the TestLinkAPIClient 
class, probably because he did not find it in the given location (testlink.
api.java.client.TestLinkAPIClient.*).
How to solve this problem?


W dniu piątek, 12 kwietnia 2019 18:41:23 UTC+2 użytkownik Ivan Fernandez 
Calvo napisał:
>
> Hi,
>
> There are many reasons to not include those classes in your pipeline code 
> I will give you a couple, one it is that you will have to allow to execute 
> a bunch of packages related to that library this would make your Jenkins 
> less secure see 
> https://wiki.jenkins.io/display/JENKINS/Script+Security+Plugin, the 
> second it is related to how we should put into pipeline, the pipeline 
> script language it is designed to orchestrate your pipeline launching your 
> build, deploy, test, ... scripts or whatever, it is not recommended to 
> introduce business logic into your pipeline code, my mate Jesse Glick 
> explains it much better than me in the following keynote "Jenkins World 
> 2017: How to Use Jenkins Less" https://www.youtube.com/watch?v=Zeqc6--0eQw
>
> so my recommendation is to put that code in a script and execute this 
> groovy script from the pipeline, you do not need to include that code in 
> the pipeline.
>
>
>
> El viernes, 12 de abril de 2019, 16:55:08 (UTC+2), Marogo Ytcutc escribió:
>>
>> I would like to use the TestLinkAPIClient class (java) in my pipeline 
>> Jenkins, so I need link these modules 
>> 
>>  to 
>> the pipeline, and then run the code below in groovy (found on the net, so 
>> it is unknown if it can work at all):
>>
>> #!/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;
>>  def api = new TestLinkAPIClient(DEVKEY, URL)
>>  TestLinkAPIResults projects = api.getProjects()
>>  api.createTestProject(...)
>>
>>
>> Ideally, it would be possible to link these modules to the pipeline after 
>> downloading them from the local SVN (where my project is built in the job) 
>> to the job workspace. My pipeline need some reference to the location of 
>> these modules in the %workspace%\testlink\api\java\client folder.
>>
>> Marogo
>>
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/e8a45718-9bfd-407b-9283-b3b047d95be5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jenkins - link a java package to pipeline

2019-04-12 Thread Ivan Fernandez Calvo
Hi,

There are many reasons to not include those classes in your pipeline code I 
will give you a couple, one it is that you will have to allow to execute a 
bunch of packages related to that library this would make your Jenkins less 
secure see https://wiki.jenkins.io/display/JENKINS/Script+Security+Plugin, 
the second it is related to how we should put into pipeline, the pipeline 
script language it is designed to orchestrate your pipeline launching your 
build, deploy, test, ... scripts or whatever, it is not recommended to 
introduce business logic into your pipeline code, my mate Jesse Glick 
explains it much better than me in the following keynote "Jenkins World 
2017: How to Use Jenkins Less" https://www.youtube.com/watch?v=Zeqc6--0eQw

so my recommendation is to put that code in a script and execute this 
groovy script from the pipeline, you do not need to include that code in 
the pipeline.



El viernes, 12 de abril de 2019, 16:55:08 (UTC+2), Marogo Ytcutc escribió:
>
> I would like to use the TestLinkAPIClient class (java) in my pipeline 
> Jenkins, so I need link these modules 
> 
>  to 
> the pipeline, and then run the code below in groovy (found on the net, so 
> it is unknown if it can work at all):
>
> #!/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;
>  def api = new TestLinkAPIClient(DEVKEY, URL)
>  TestLinkAPIResults projects = api.getProjects()
>  api.createTestProject(...)
>
>
> Ideally, it would be possible to link these modules to the pipeline after 
> downloading them from the local SVN (where my project is built in the job) 
> to the job workspace. My pipeline need some reference to the location of 
> these modules in the %workspace%\testlink\api\java\client folder.
>
> Marogo
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/0adea877-652d-48f7-9e57-38f77b488d9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Jenkins - link a java package to pipeline

2019-04-12 Thread Marogo Ytcutc
I would like to use the TestLinkAPIClient class (java) in my pipeline 
Jenkins, so I need link these modules 

 to 
the pipeline, and then run the code below in groovy (found on the net, so 
it is unknown if it can work at all):

#!/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;
 def api = new TestLinkAPIClient(DEVKEY, URL)
 TestLinkAPIResults projects = api.getProjects()
 api.createTestProject(...)


Ideally, it would be possible to link these modules to the pipeline after 
downloading them from the local SVN (where my project is built in the job) 
to the job workspace. My pipeline need some reference to the location of 
these modules in the %workspace%\testlink\api\java\client folder.

Marogo

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/195bb62e-9067-428c-827a-f0d037715ee4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.