As part of my Jenkins pipeline I want to zip my output directory to a shared drive and I have a batch script that works wonderfully when running it through a shell, but when Jenkins runs it the file_names argument to 7zip goes missing and it zips the entire project folder instead.
The batch script looks as follows, where GGProjectName has a string value(no special characters) and CHANGESET is an integer
set path=D:\Data\Builds\%GGProjectName%\development
call "C:\Program Files\7-Zip\7z.exe" a -tzip %path%\%GGProjectName%-%CHANGESET%.zip .\Build\
Calling the batch script through a shell gives the following output with GGProjectName=ProjectName and CHANGESET=2:
E:\Jenkins\ProjectName\ProjectName_Main\workspace>set path=D:\Data\Builds\ProjectName\development
E:\Jenkins\ProjectName\ProjectName_Main\workspace>CALL "C:\Program Files\7-Zip\7z.exe" a -tzip D:\Data\Builds\ProjectName\development\ProjectName-2.zip E:\Jenkins\ProjectName\ProjectName_Main\workspace\Build\
7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
Scanning the drive:
23 folders, 439 files, 718413046 bytes (686 MiB)
Creating archive: D:\Data\Builds\ProjectName\development\ProjectName-2.zip
Items to compress: 462
Files read from disk: 439
Archive size: 137063321 bytes (131 MiB)
Everything is Ok
Getting Jenkins to run the same script gives the following output, with GGProjectName=ProjectName and CHANGESET=77:
17:04:21 E:\Jenkins\ProjectName\ProjectName_Main\workspace>set path=D:\Data\Builds\ProjectName\development
17:04:21
17:04:21 E:\Jenkins\ProjectName\ProjectName_Main\workspace>CALL "C:\Program Files\7-Zip\7z.exe" a -tzip D:\Data\Builds\ProjectName\development\ProjectName-77
17:05:57
17:05:57 7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
17:05:57
17:05:57 Scanning the drive:
17:05:57 856 folders, 14893 files, 2074486211 bytes (1979 MiB)
17:05:57
17:05:57 Creating archive: D:\Data\Builds\ProjectName\development\ProjectName-77.zip
17:05:57
17:05:57 Items to compress: 15749
17:05:57
17:05:57
17:05:57 Files read from disk: 14893
17:05:57 Archive size: 453305828 bytes (433 MiB)
17:05:57 Everything is Ok
I've identified the issue as Jenkins somehow cutting off the last argument to the call to 7z.exe, though I have no idea what causes it.
The Jenkins stage that runs the script is extremely straightforward so I have a hard time seeing that as the cause.
stage('Deploy') {
steps {
bat 'publish.bat'
}
}
I'm running Jenkins 2.204.2 on a Windows machine.