I have to start a Maven build with a md5 hash as parameter:
mvn clean verify -Dchecksum=ea25acae60d51e86993efcc6757b31cd
This hash has to be generated from the contents of two configuration files (A.xml, B.xml)
The build is executed on a Jenkins slave running on Windows. So I have implement a PowerShell script:
$config_a = [IO.File]::ReadAllText("A.xml") $config_b = [IO.File]::ReadAllText("B.xml") $enc = [system.Text.Encoding]::UTF8 $data = $enc.GetBytes($config_a+$config_b) $md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider $hash = [System.BitConverter]::ToString($md5.ComputeHash($data)).ToLower().Replace("-", "") write-host "Calculated Hashsum: " $hash "CHECKSUM=$hash" | Out-File -Encoding ASCII ".\checksum.properties"
In the Jenkins job the generated properties file is read with the EnvInject Plugin to create the environment variable CHECKSUM
.
In the build step ‘Invoke Maven top level’ the Maven build can now be started like this:
clean verify -Dchecksum=$CHECKSUM
Note: without ‘-Encoding ASCII’ the properties file is written as ‘Unicode’. The ‘EnvInject Plugin’ then creates a wrong environment variable and the build fails with:
FATAL: Invalid environment variable name: "ÿþchecksum" java.lang.IllegalArgumentException: Invalid environment variable name: "ÿþCHECKSUM"