Home > database >  How to combine multiple files in a zipFile in Jenkins?
How to combine multiple files in a zipFile in Jenkins?

Time:11-30

I wish to combine 3 files into a zipFile in my jenkins build. I have taken a look at these two sources (1, 2), but I cannot understand what that means for my example? My example is the following (generic example to hide real names):

zip zipFile: "myZip.zip", archive: true, dir: './someLocation1', glob: 'file1.py*'
zip zipFile: "myZip.zip", archive: true, dir: './someLocation2', glob: 'file2.py*'
zip zipFile: "myZip.zip", archive: true, dir: './someLocation3', glob: ''

The top two lines of code I want a specific file from each location, and the bottom line I want all files from that location, illustrated with the empty string (reference) glob: ''. Of course this way is not correct and produces an error when it gets to the second line because myZip.zip already exists.

I want these files to be in the same zip because I want to then send the zip to storage. How can I write this to achieve what I want? Is this the right way to solve this problem?

CodePudding user response:

You can do something like this. First copy all the files you need to a temp directory and then Zip that directory.

sh'''
mkdir tempDir
cp ./someLocation1/file1.py tempDir
cp ./someLocation2/file2.py tempDir
cp -r ./someLocation3/* tempDir/
'''

zip zipFile: "myZip.zip", archive: true, dir: './tempDir'
  • Related