Python Forum
JenkinsFile to create a Python venv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JenkinsFile to create a Python venv
#1
Hi, I am working to create a new pipeline to run test cases from my Python repository in Jenkins. have created a 'Jenkinsfile' defining the different stages that I would need, however I'm unable to create a virtual environment for Python to run.
Can someone help what i am missing?

#!/usr/bin/env groovy

properties([
	pipelineTriggers([
		pollSCM('*/1 * * * *')
	]),
	disableConcurrentBuilds()
])

node {
	env.GIT_PROJECT_NAME = "*******"					
	//PYTHON_VERSION = "3.12"  // Specify the Python version
	VENV_DIR = "venv"       // Directory for the virtual environment
	ALLURE_RESULTS_DIR = "allure-results" // Directory for Allure results	 	
	
	// Credentials for TFSFSService SSH user
	def GIT_CREDENTIALS_ID = '*******'

	def branchName = "${env.BRANCH_NAME}"
	
	try {
		stage ('Checkout') {
	        git(
				poll: true,
				url: "[email protected]:v3/d***d/***/${env.GIT_PROJECT_NAME}",
				credentialsId: GIT_CREDENTIALS_ID,
				branch: branchName
	        )			
		}
		stage('Setup Python Environment') {																
			// Create a virtual environment
			echo 'python --version'
			
			bat 'python3 -m venv ${VENV_DIR}' 
			bat '${VENV_DIR}\\bin\\activate'
		}
	}
	catch (e) {		
		throw e	        
	}
}
Getting the below error currently:

Error:
[Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Setup Python Environment) [Pipeline] echo python --version [Pipeline] bat C:\Users\Jenkins\AppData\Local\Jenkins\.jenkins\workspace\st_thymeit-auto-base_development>python -m venv ${VENV_DIR} Actual environment location may have moved due to redirects, links or junctions. Requested location: "C:\Users\Jenkins\AppData\Local\Jenkins\.jenkins\workspace\st_######\${VENV_DIR}\Scripts\python.exe" Actual location: "D:\jenkins\workspace\st_####\${VENV_DIR}\Scripts\python.exe" [Pipeline] bat C:\Users\Jenkins\AppData\Local\Jenkins\.jenkins\workspace\st_thymeit-auto-base_development>${VENV_DIR}\bin\.activate The system cannot find the path specified. [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE
Reply
#2
There are packages available here. I haven't used any of them, so you will need to examine for usability.
Reply
#3
(Sep-21-2024, 06:53 AM)Larz60+ Wrote: There are packages available here. I haven't used any of them, so you will need to examine for usability.

Thank you Larzo, but I'm looking for groovy script that can help me create a virtual environment in Jenkins. currently, I believe it's a path issue that Im unable to rectify.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How does venv update $PATH without activating on Windows? bottomfeeder 3 666 Mar-13-2025, 01:46 PM
Last Post: DeaD_EyE
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 2,001 Jun-04-2024, 10:55 PM
Last Post: Drone4four
  my venv is not loading njoki 1 1,655 Mar-20-2024, 10:41 AM
Last Post: snippsat
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 4,573 May-10-2023, 02:13 PM
Last Post: Calab
  Python venv and PIP version issue JanOlvegg 2 3,200 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Visual Studio Code venv ibm_db error mesi1000 7 4,886 Nov-13-2022, 12:36 AM
Last Post: snippsat
  pip and venv virtual environments soupworks 2 2,962 Dec-30-2020, 11:38 PM
Last Post: soupworks
  Not able to set up a virtual environment with venv mohanp06 7 19,901 Oct-27-2020, 12:18 PM
Last Post: snippsat
  Creating virtual environment with venv arilev 1 2,707 Dec-16-2019, 05:14 PM
Last Post: Larz60+
  Pycharm community edition venv folder tantony 3 4,208 Oct-18-2019, 12:28 PM
Last Post: tantony

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020