通过Jenkins kubernetes插件在Kubernetes上使用Packer容器

问题描述

我有一个运行在EKS上的Jenkins主服务器,并且启用了Jenkins Kubernetes插件

这一切似乎都很好,我可以完成简单的工作量。

但是我无法工作的是Packer容器,我无法锻炼如何将git仓库中的.json文件传递到容器的“ build”命令。因为Packer容器仅接受有限的命令,例如“ build”,“ version”我无法抓取外壳以查看是否存在我的.json文件...

有没有人有想法/有没有人在构建这种类型的作品?

这是我的Jenkinsfile

podTemplate(containers: [
    containerTemplate(name: 'packer',image: 'hashicorp/packer:latest',ttyEnabled: true,command: 'packer build -on-error=ask',args: '/home/jenkins/agent/workspace/test-pipeline/firstrun.json',envVars: [(envVar(key: "PACKER_LOG",value: "1" ))],),]) {

  node(POD_LABEL) {
    stage('Get a Packer project') {
      git url: 'https://github.com/my-git-repo-that-contains-firstrun.json.git',credentialsId: 'jenkins-credentials-id'
      container('packer') {
        stage('Build a packer project') {
          echo 'Building Packer...'
        }
      }
    }
  }
}

这是日志输出

Sep 10,2020 11:17:06 AM SEVERE org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher logLastLines
Error in provisioning; agent=KubernetesSlave name: test-pipeline-70-d313m-p6qfj-r862m,template=PodTemplate{,name='test-pipeline_70-d313m-p6qfj',namespace='infra',label='test-pipeline_70-d313m',nodeUsageMode=EXCLUSIVE,workspaceVolume=EmptyDirWorkspaceVolume [memory=false],containers=[ContainerTemplate{name='packer',image='hashicorp/packer:latest',command='packer build -on-error=ask',args='/home/jenkins/agent/workspace/test-pipeline/firstrun.json',ttyEnabled=true,envVars=[keyvalueEnvVar [getValue()=1,getKey()=PACKER_LOG]]}],annotations=[org.csanchez.jenkins.plugins.kubernetes.PodAnnotation@aab9c821,org.csanchez.jenkins.plugins.kubernetes.PodAnnotation@c92c82e4]}. Container packer exited with error 1. Logs: 2020/09/10 11:17:04 [INFO] Packer version: 1.6.2 [go1.13.15 linux amd64]
2020/09/10 11:17:04 Checking 'PACKER_CONfig' for a config file path
2020/09/10 11:17:04 'PACKER_CONfig' not set; checking the default config file path
2020/09/10 11:17:04 Attempting to open config file: /root/.packerconfig
2020/09/10 11:17:04 [WARN] Config file doesn't exist: /root/.packerconfig
2020/09/10 11:17:04 Setting cache directory: /packer_cache
"/home/jenkins/agent/workspace/test-pipeline/firstrun.json": stat /home/jenkins/agent/workspace/test-pipeline/firstrun.json: no such file or directory
2020/09/10 11:17:04 [INFO] (telemetry) Finalizing.
2020/09/10 11:17:05 waiting for all plugin processes to complete...

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)