我已经在Jenkins凭证中添加了两个名为PRIVATE-KEY和PUBLIC-KEY的秘密文件。如何将这两个文件复制到作业中的/src/resources目录?
我有以下代码片段
withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'my-private-key'),
file(credentialsId: 'PUBLIC_KEY', variable: 'my-public-key')]) {
//how to copy, where are those files to copy from?
}发布于 2018-03-24 23:28:52
好了,我想我做到了。my-private-key变量是秘密的路径,所以我必须将该秘密复制到我需要的目的地。
withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'my-private-key'),
file(credentialsId: 'PUBLIC_KEY', variable: 'my-public-key')]) {
sh "cp \$my-public-key /src/main/resources/my-public-key.der"
sh "cp \$my-private-key /src/main/resources/my-private-key.der"
}发布于 2020-06-24 07:42:51
这两种解决方案都适用于特定的OS(win,unix)。有一些基本的功能来检查是系统unix的isUnix()。相反,您可以使用任何机器的读/写基本方法。
withCredentials([file(credentialsId: PRIVATE_KEY, variable: 'my_private_key'),
file(credentialsId: PUBLIC_KEY, variable: 'my_public_key')]) {
writeFile file: 'key/private.pem', text: readFile(my_private_key)
writeFile file: 'key/public.pem', text: readFile(my_public_key)
}发布于 2019-08-01 16:36:30
根据@Humberds的回答,powershell的等价物是:
withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'my-private-key')]) {
bat "powershell Copy-Item $appSettings -Destination src\\main\\resources "
}https://stackoverflow.com/questions/49460520
复制相似问题