Home > other >  how does jenkins recognize paths inside a python script?
how does jenkins recognize paths inside a python script?

Time:10-02

I have a python script that points to some file names and log files and I have jenkins to run the script, when run locally from my system the code works fine.

The way I access my folders in python: folder_artifacts_data = 'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Artifacts/' path_to_log_file ='C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log'

but when I try to run the same using jenkins, I get the following error:

No such file or directory: /opt/jenkins/workspace/confluencetest_scheduled/C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log

Now, I tried different file paths and used r-strings

folder_artifacts_data = r'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Artifacts/' path_to_log_file =r'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log'

I see that jenkins has accepted the log file, because I see the logs written, but the moment it reaches folder_artifacts_data it throws the error that the file path do not exist.

Could someone help?

Update Now I have added relative paths, like: folder_artifacts_data0 = 'C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Artifacts/' folder_artifacts_data = os.path.relpath(folder_artifacts_data0) path_to_log_file0 ='C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log' path_to_log_file = os.path.relpath(path_to_log_file0)

that outputs paths like: ..............\Rhea\OneDrive -Area\Rhea\Metrics_Configuration\Artifacts

and

..............\Rhea\OneDrive -Area\Rhea\Metrics_Configuration\Logfiles\Logfile.log

this works well in my local, again I get No such file or directory: /opt/jenkins/workspace/confluencetest_scheduled/C:/Users/Rhea/OneDrive -Area/Rhea/Metrics_Configuration/Logfiles/Logfile.log while running from jenkins.

CodePudding user response:

Ok the problem was that there was no such file name inside the workspace of the jenkins job, how do we make it aware of the local folder ?

Using docker volumes. I have made necessary change(ie added volumes) and now it works.

  • Related