我已经为Jenkins凭证添加了2个秘密文件,名称为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?
}
好吧,我想我成功了。 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"
}
继@Humberds回答之后,powershell的等价物是:
withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'my-private-key')]) {
bat "powershell Copy-Item $appSettings -Destination src\\main\\resources "
}