how to download and save files to jenkins from another url?

168 Views Asked by At

I have a python script running on cloudbees, During the earlier iteration of the project when the code was running on the local machine, this python script used to download a .zip file from another host machine and used to store the zip file in a local folder from which the contents were read again by the script and posted onto a website.

Now, we are trying to move the script to cloudbees and although I could make a connection with the host machine, I could not download the file into the local folder for jenkins do not recognize a windows path, alternatively I was told that the downloaded zip file could be kept in the cloudbees/jenkins itself. Can someone suggest me how to do it? any useful links or libraries for the same? This is the code I used to download file from a jenkins server into local machine, it runs perfectly when run from my local machine, but when run from cloudbees it throws error that it cannot recognise the path name_of_file_to_be_downloaded, I understand that it is because its a windows path name on a local machine. But how do I handle and keep the downloaded .zip file in cloudbees instance and later push it to artifactory?

jenkins_session = requests.Session()
jenkins_session.auth = (jenkins_auth_userid, jenkins_user_token)
retry = Retry(connect=10,backoff_factor=5)
adapter = HTTPAdapter(max_retries=retry)
jenkins_session.mount('http://', adapter)
jenkins_session.mount('https://', adapter)
req = jenkins_session.get(url)
print(req.status_code)
with open(name_of_file_to_be_downloaded, 'wb') as output:
    output.write(req.content)
    output.close
0

There are 0 best solutions below