Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins 使用Jenkingfile将密钥文件复制到文件夹_Jenkins_Jenkins Pipeline - Fatal编程技术网

Jenkins 使用Jenkingfile将密钥文件复制到文件夹

Jenkins 使用Jenkingfile将密钥文件复制到文件夹,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我正在使用jenkins脚本文件。 我将.key文件存储在jenkins文件中(所有env文件都存在)。 我需要把那个文件复制到代码文件夹。 就像我想在src/auth/keys中存储device.key 然后将对管道中的代码运行测试。 我使用的是脚本化的Jenkins文件。我找不到任何方法来解决这个问题 node{ def GIT_COMMIT_HASH stage('Checkout Source Code and Logging Into Registry') {

我正在使用jenkins脚本文件。 我将.key文件存储在jenkins文件中(所有env文件都存在)。 我需要把那个文件复制到代码文件夹。
就像我想在
src/auth/keys
中存储
device.key

然后将对管道中的代码运行测试。 我使用的是脚本化的Jenkins文件。我找不到任何方法来解决这个问题

node{
  def GIT_COMMIT_HASH
  stage('Checkout Source Code and Logging Into Registry') {
          echo 'Logging Into the Private ECR Registry'
          checkout scm
          sh "git rev-parse --short HEAD > .git/commit-id"
          GIT_COMMIT_HASH = readFile('.git/commit-id').trim()
          # NEED TO COPY device.key to /src/auth/key
        }
  stage('TEST'){
    nodejs(nodeJSInstallationName:'node'){
      sh 'npm install'
      sh 'npm test'    
    }
 }
}
我是如何解决这个问题的:

  • 我安装了配置文件提供程序插件

  • 我为每个环境添加了自定义文件

  • 在jenkins文件中,我将项目中的配置文件替换为jenkins提供的配置文件:
    
    阶段('添加配置文件'){
    台阶{
    configFileProvider([configFile(文件ID:'Jenkins存储文件的ID',targetLocation:'项目中目标文件的相对路径')){
    //一些块,可能是调试的友好回音
    } } }
    
    请参阅,因为它能够替换XML和json文件以及许多其他文件中的令牌