Run python script in jenkins

39,002

Adds the ability to execute python scripts as build steps. Other than that, this plugin works pretty much like the standard shell script support

Per the docs of the plugin. Though I have not used this plugin through pipeline, from job perspective, you have to just provide .py script (filename and path), in a same way you provide for shell/powershell script.

Similarly, even for python, you'll be executing the script on a node, which will be either Linux or Windows.

So, it would work as below :

stage('build') {
    steps {
        sh 'python abc.py'
    }
}

References : https://www.jenkins.io/doc/pipeline/tour/hello-world/

Lookout for "Python" block.

Share:
39,002
Abhishek Parmar
Author by

Abhishek Parmar

Updated on July 09, 2022

Comments

  • Abhishek Parmar
    Abhishek Parmar almost 2 years

    I want to run a python script from Jenkins using Jenkinsfile. Is there any way to run it directly from Jenkinsfile.

    I found python plugin(Click Here) in Jenkins to run a script, but there is no proper documentation for this plugin. It would be very helpful if anyone explains how to integrate this plugin with Jenkinsfile.

  • Abhishek Parmar
    Abhishek Parmar about 4 years
    I don't think it'll work without python agent... In reference there's agent { docker { image 'python:3.5.1' } }
  • Abhishek Parmar
    Abhishek Parmar about 4 years
    I wanna run it in any agent
  • saurabh14292
    saurabh14292 about 4 years
    It should not matter if you are running on agent or master itself. What you'll need is python installed and be available in PATH variable, else, you can execute by providing full path such as /usr/bin/python or wherever python is installed. Reference shows docker image because the node is container based. You can have node as a VM too.
  • Chang Zhao
    Chang Zhao almost 3 years
    what if the jenkins is running on docker container ?