Epligam
Epligam

Reputation: 783

How can I run python script from Jenkins declarative pipeline?

How can I run python script from Jenkins declarative pipeline?
The machine is Windows and I already have python 2.7 installed on it. I tried several ways:

    def return_val = bat(script: 'C:\\aaa.py', returnStdout: true)
    python  C:\\aaa.py
    python.exe  C:\\aaa.py
    python returnStatus: true, script: 'C:\\aaa.py'

Upvotes: 1

Views: 6687

Answers (2)

NIK
NIK

Reputation: 1199

I believe Creating your first Pipeline and Microsoft PowerShell Support for Pipeline should answer your question as below,

    pipeline {
    agent { docker { image 'python:3.5.1' } }
    stages {
        stage('build') {
            steps {
                powershell 'python --version'
            }
        }
     }
   }

Upvotes: 0

Ulbe
Ulbe

Reputation: 121

I don't have a windows instance to try this on, but I think your first line is on the right track.

The problem is that you're trying to run the python file directly. According to pythoncentral you should run python.exe and pass your .py file as an argument.

On the command line you'd do the following:

C:\path\to\python.exe C:\\aaa.py

Which we can put into your first line to get:

def return_val = bat(script: 'C:\path\to\python.exe C:\\aaa.py', returnStdout: true)

Upvotes: 1

Related Questions