1
votes

Referring to the document: https://jenkinsci.github.io/job-dsl-plugin/#path/freeStyleJob-steps-python I am trying to configure my job automatically through groovy. The job will execute a python code piece. Something like this:

import os
from Reporting.MSTest import MSTest
jsonFile = os.path.join(os.getenv('temp')

Here is the code snippet. Which will add above python script in the job build steps

# the job name is "jobName"
jobA = freeStyleJob("jobName")
jobA.with {
    steps {
        python {
            command(String 'import os')
        }
    }
}

It not working. Please help!

1
The command contains the filename for a python script, not python code - KeepCalmAndCarryOn

1 Answers

1
votes

Jenkins DSL 'python' refers to the Shining Panda plugin not the python script plugin. This is worth bearing in mind if like me you use the python script plugin.

Sadly the python script plugin doesn't have an API but you can use a configure closure to add this direct.

configure { node ->
  node / builders / 'hudson.plugins.python.Python' / command << readFileFromWorkspace('<script location>')
}

This has worked for me as I like to read from script for simplicity or you could add direct with 'command( 'import os' )'