1

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'

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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'
            }
        }
     }
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.