简体   繁体   中英

How to configure Jenkins to run Python scripts?

I installed python via anaconda on an EC2 Ubuntu Instance.

The command which python returns */home/ubuntu/anaconda3/bin/python* Jenkins is instead installed in */var/lib/jenkins*

I am trying to run a simple "Hello World" script saved on a file named *test.py* and located within the */home/ubuntu/scripts/* folder.

While running *python /home/ubuntu/scripts/test.py* works on terminal, it fails as an "Execute shell" build step in Jenkins.

Why and how do I configure Jenkins to run python scripts step by step?

The issue was that the anaconda python installation was only available to the user "ubuntu". For Jenkins to be able to run python scripts, the "jenkins" user needs to use that installation.

To solve the problem, this is what I did:

  1. Logged in as jenkins with the command sudo su -s /bin/bash jenkins
  2. Edited the python install location as export PATH=/home/ubuntu/anaconda3/bin:$PATH
  3. Checked that the path is correct through which python
  4. Logged back as ubuntu user
  5. Restarted Jenkins through sudo service jenkins restart (not sure if necessary)

Now I can run python scripts through Jenkins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM