How to configure Jenkins to run Python scripts? - python

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:
Logged in as jenkins with the command sudo su -s /bin/bash jenkins
Edited the python install location as export PATH=/home/ubuntu/anaconda3/bin:$PATH
Checked that the path is correct through which python
Logged back as ubuntu user
Restarted Jenkins through sudo service jenkins restart (not sure if necessary)
Now I can run python scripts through Jenkins.

Related

How do I activate a VSCode environment from ssh?

I am currently using VS Code on a server (through SSH). Everything works fine, and I installed Python packages and work with Python notebooks.
Now, I want to login to the server (not a problem) and run the Python code I created on VSCode, rather than executing it remotely.
My main issue is that I am not sure how to activate the Python environment (if there is one) that VSCode server's run so that the code can execute.
Is that possible?
I see I have a .vscode directory in my home directory, and there are package installation there.
After connecting vscode remotely, you can use it as a regular vscode, which is no different from running Python files locally:
install python
install pylance extension
choose correct interpreter
edit your code and run the python file.

Run python script as non-root user

I installed python3 and required module with root access. But, When I try to run the scrip as non-root user. I am getting following error:
No module found Error.
What is the right way to run the python3 script as non-root user. virtualenv works fine If interactively runs it. But, I need to run it from nifi. So, I should be able to execute it without virtualenv.
You would need to install the module as non-root, or more specifically, the user account that runs NiFi.
You shouldn't be using sudo with pip anyway
The easiest way to do this would be to install Anaconda (big Python distribution with a nice installer) in a location accessible to NiFi and chown the Anaconda folder to the NiFi service account user.

Unable to run taurus tests in jenkins. Build console log says bzt command not found

I am trying to run Jmeter tests with the help of taurus in jenkins with performance plugin. In my yml file I have passed the scenarios to run jmx scripts and in jenkins I am using execute shell to run my tests
bzt test_suite.yml -report
I have also set the current directory as my workspace in jenkins. So, when I build the project in build console I get the following output
Running as SYSTEM
Building in workspace C:\Users\muhammad.taus\PycharmProjects\PerfAutomationFramework
[PerfAutomationFramework] $ sh -xe C:\Users\MUHAMM~1.TAU\AppData\Local\Temp\jenkins2737910596558040446.sh
+ bzt test_suite.yml -report
C:\Users\MUHAMM~1.TAU\AppData\Local\Temp\jenkins2737910596558040446.sh: line 2: bzt: command not found
Build step 'Execute shell' marked build as failure
Creating parser with percentiles:'0,50,90,100,' filterRegex:
Cannot detect file type because of error: Failed to copy C:\Users\muhammad.taus\PycharmProjects\PerfAutomationFramework\stats.xml to C:\Users\muhammad.taus\.jenkins\jobs\PerformanceAutomation\builds\36\temp\stats.xml
Finished: FAILURE
But previously the tests used to run fine on my host. I installed taurus using pip and in CMD When I type bzt it gets taurus, also when I type py it picks python and also I have setup JMETER_HOME and in cmd when I used jmeter it opens Jmeter. I am not sure what happened but I am not able to execute the tests anymore. The only thing I remember is changing python version from 32 bit to 64 bit, But I am sure that is not causing the problem. Please if anyone can help me in this regard it would be great.
You have some weird mix of Linux and Windows and your question doesn't contain sufficient level of details in order to troubleshoot the issue.
Use the full path to python executable in your shell script
Instead of bzt use /path/to/python -m bzt.cli your_config.yml
If you get No module named bzt install it using pip:
python -m pip install bzt
If python executable is not found, try python3 instead
More information:
Installing and Upgrading Taurus
Integrating Taurus with Jenkins
How to Run Taurus with the Jenkins Performance Plugin

ksh : ./bin/python2.7: cannot execute

Hi all I am working with IBM AIX remote server and cannot get the python inside the virtualenv to execute, though I have activated the virtualenv. I created the virtualenv on my mac machine with the all the dependencies installed required to run the project as I don't have the admin privileges on the AIX box and need to deploy and run my app on the server.
I was able to activate the virtual environment on the aix box by running the below command
. ./project_name/bin/activate
I tried running the file using the path to the python inside the virtualenv
/u/.../project_name/bin/python2.7 myfile.py
but go the error
ksh: ./bin/python2.7: cannot execute
Whenever i try to check the python that is currently being executed I get the system python path as a result
which python
/bin/python
I want it to execute the python inside the virtualenv and use the libraries that I have installed in there for the app I want to run. Any help would be appreciated.

Bash script equivalent in windows to run pip and python commands?

I have a python code which I need to send it to a client who will run it windows.
The python code works on a few imported modules mentioned in requirements.txt:
requests==2.11.1
xlwt==1.1.2
beautifulsoup4==4.5.1
If I have to execute the code in windows, I’ll have manually ask the client to download these above modules before running the script.
I have created a bash script ( for linux), which is such:
sudo pip install -r requirements.txt
echo "Requirements met"
python ./isb.py
What is the bash script equivalent in windows? I want to client to only execute 1 file which executes other remaining files.
Can an executable be made for a task like this?
The code and other files are here if need be.
I has similar task in the past. So I just used a tool py2exe which builds a standalone executable and it resolves dependencies at build time. A valid python interpreter will be included to the build. So your client can just execute this standalone exe file by double-click or from cmd shell.

Categories