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'
            }
        }
    }
}
4
  • As you are using one of the hello world examples of Jenkins (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? Commented Mar 26, 2019 at 6: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 Commented Mar 26, 2019 at 6:30
  • Where is your docker host, on same Windows machine as of Jenkins? and have you configured it in the Jenkins global configuration. Commented Mar 26, 2019 at 7:12
  • What is the console log for the job? Commented Mar 26, 2019 at 13:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
Please have a look here.https://stackoverflow.com/questions/45140614/jenkins-pipeline-sh-fail-with-cannot-run-program-nohup-on-windows

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.