4

I want to run a python file or set of python commands via a JenkinsFile. How do I approach this?

I run the code below and My Jenkins Job never finishes.

pipeline {
    agent { docker { image 'python:3.5.1' } }
    stages {
        stage('build') {
            steps {
                sh 'python --version'
            }
        }
    }
}
A.D.
  • 17
  • 2
Pritish
  • 191
  • 1
  • 1
  • 7
  • As you are using one of the hello world examples of Jenkins (https://jenkins.io/doc/pipeline/tour/hello-world/) your code should work. Is your Jenkinsfile placed in your repository? Or can you provide more jenkins output? – Michael Kemmerzell Mar 26 '19 at 06:07
  • Yes, I am using same jenkins example as mentioned in Windows machine.. Caused: java.io.IOException: Cannot run program "nohup" (in directory "D:\OCIPlatformIDC\jenkins\workspace\githubpipeline"): CreateProcess error=2, The system cannot find the file specified – Pritish Mar 26 '19 at 06:30
  • Where is your docker host, on same Windows machine as of Jenkins? and have you configured it in the Jenkins global configuration. – SunilThorat Mar 26 '19 at 07:12
  • What is the console log for the job? – Matthew Schuchard Mar 26 '19 at 13:44

1 Answers1

1

I got your pipeline working by following the below steps:

  1. Create a Pipeline job with the code you posted in the question.
pipeline {
    agent { docker { image 'python:3.5.1' } }
    stages {
        stage('build') {
            steps {
                sh 'python --version'
            }
        }
    }
}

enter image description here

  1. Install docker on the virtual machine console and add the jenkins user to docker group
sudo apt install docker.io
sudo systemctl enable docker
sudo systemctl start docker
docker --version
> Docker version 18.09.2, build 6247962
sudo usermod -a -G docker jenkins
  1. Run the job, you must get a success and python version like in below screenshot.

enter image description here

Feel free to ask any questions, if required.

Mo Ziauddin
  • 380
  • 1
  • 13
  • Jenkins installed in Windows, Docker as well. So do I have to add the Jenkin user to docker group? I am getting below mentioned error for jenkins build: Caused: java.io.IOException: Cannot run program "nohup" (in directory "D:\OCIPlatformIDC\jenkins\workspace\githubpipeline"): CreateProcess error=2, The system cannot find the file specified – Pritish Mar 26 '19 at 06:37
  • Please have a look here.`https://stackoverflow.com/questions/45140614/jenkins-pipeline-sh-fail-with-cannot-run-program-nohup-on-windows` – Mo Ziauddin Mar 27 '19 at 03:45