Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an built-in way or plugin to get Jenkins to produce SHA256 hashes for my artifacts?

My new corporate overlords require that I have a SHA256 hash of each artifact on the customer portal. Of course, I can generate this myself or do it in build script or Makefile, but this feels like the sort of thing Jenkins would be able to do.

like image 397
kbyrd Avatar asked Dec 20 '22 02:12

kbyrd


2 Answers

If your builds are running on Unix/Linux, from your Pipeline/Jenkinsfile, you can shell out to sha256sum:

sha256sum = sh(returnStdout: true, script: "sha256sum '${fileName}'")

If your builds are running on Windows, you can shell out to Get-FileHash (I haven't tested this):

sha256sum = powershell(
  returnStdout: true, 
  script: "Get-FileHash -Algorithm sha256 -Path '${fileName}' | Select -ExpandProperty Hash"
)
like image 88
jayhendren Avatar answered Dec 26 '22 10:12

jayhendren


You can use the jenkins utilty step: sha256

https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/

def hash = sha256 file: 'myfile.txt'
like image 30
Emmanuel Osimosu Avatar answered Dec 26 '22 10:12

Emmanuel Osimosu