如何复制Jenkins秘密文件

问题描述 投票:12回答:1

我已经为Jenkins凭证添加了2个秘密文件,名称为PRIVATE-KEYPUBLIC-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?
}
jenkins groovy
1个回答
32
投票

好吧,我想我成功了。 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"
}

0
投票

继@Humberds回答之后,powershell的等价物是:

withCredentials([file(credentialsId: 'PRIVATE_KEY', variable: 'my-private-key')]) {
  bat "powershell Copy-Item $appSettings -Destination src\\main\\resources "
}
© www.soinside.com 2019 - 2024. All rights reserved.