one more thing if you want to have those scripts shared across pipelines 
you can use the shared library.
You can define those scripts as resources in the shared library and invoke 
them directly

def stdout = bat(returnStdout: true, script: "*groovy -e 
'${libraryResource('my-script.groovy'))}'* ")

see https://www.jenkins.io/doc/book/pipeline/shared-libraries/#loading-resources
El miércoles, 14 de julio de 2021 a las 20:15:38 UTC+2, Ivan Fernandez 
Calvo escribió:

> no, it is not possible, the groovy code is executed in the Jenkins 
> controller by design, it is designed to execute simple logic of 
> orchestration logic, if you want to execute heavy logic you should do it on 
> the agents by using steps that run scripts or processes on the agent. 
>
> pipeline {
>    agent { label 'scdc-generic-w10x64' }
>    options {
>       timestamps()
>    }
>    stages {
>       stage('Log ip') {
>         steps {
>             script {
>                bat "ipconfig -all"   // *** Gets executed on Jenkins Agent 
> ***
>                def stdout = bat(returnStdout: true, script: "*groovy 
> *my-script.groovy" 
> // *** Gets executed on Jenkins Agent ***
>                echo "stdout"
>             }
>          }
>       }
>    }
>    post {
>       always {
>          cleanWs()
>       }
>    }
> }
>
> the script can be whatever you want groovy, python, PowerShell, or a 
> simple binary, the only that you have to have is the script interpreter 
> installed in your Jenkins agent 
> take a look at this fantastic Jesse Glick presentation to know why 
> https://www.youtube.com/watch?v=Zeqc6--0eQw
> El martes, 13 de julio de 2021 a las 22:49:57 UTC+2, raviraj...@gmail.com 
> escribió:
>
>> I have a question regarding the execution of JSL scripts on the Jenkins 
>> Agent node. I noticed JSL scripts get executed only on Jenkins Master, is 
>> it possible to run the JSL script on Jenkins Agents?
>>
>> I have multiple stages in my Pipeline and I wish to run those stages on 
>> different Jenkins Agent nodes. 
>>
>> My primary motivation for using JSL is end-to-end Pipeline testability 
>> during development using “replay”, where I can modify Jenkinsfile as well 
>> as scripts from JSL.
>>
>> This is a snippet of my Pipeline --
>>
>> pipeline {
>>    agent { label 'scdc-generic-w10x64' }
>>    options {
>>       timestamps()
>>    }
>>    stages {
>>       stage('Log ip') {
>>         steps {
>>             script {
>>                bat "ipconfig -all"   // *** Gets executed on Jenkins 
>> Agent ***
>>                foo = jsl.foo.new(this) // foo is a Groovy class in JSL
>>                foo.logIpAddress()   // *** Gets executed on Jenkins 
>> Master ***
>>             }
>>          }
>>       }
>>    }
>>    post {
>>       always {
>>          cleanWs()
>>       }
>>    }
>> }
>>
>>

-- 
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/04713271-b830-4982-a20d-478e5a857724n%40googlegroups.com.

Reply via email to