在启动时覆盖Jenkins的config.xml

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

我正在K8S群集中设置Jenkins机器,并希望我的Kubernetes群集的云属性已预先配置。

出于这个原因,我想在启动时加载自定义的qazxsw poi文件。

我的config.xml目前位于名为config.xml的configMap中,并包含我编辑的整个XML文件。

现在使用我正在使用的Jenkins Image,它会加载jenkins-config下的所有配置

这意味着/var/jenkins_home/文件在config.xml下。 /var/jenkins_home当然是坚持不懈的。

我将我的configMap作为VolumeMount引入。

我的deployment.yaml文件是:

/var/jenkins_home

现在我可以访问我的pod并验证新配置确实存在,但我的Jenkins正在给出如下错误:

spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: jenkins
        release: 1.1.1
    spec:
      containers:
        - name: jenkins
          image: jenkins-master:1.0
          env:
            - name: JAVA_OPTS
              value: -Djenkins.install.runSetupWizard=false
          ports:
            - name: http-port
              containerPort: 8080
            - name: jnlp-port
              containerPort: 54000
          volumeMounts:
            - name: jenkins-home
              mountPath: /var/jenkins_home
              readOnly: false
            - name: jenkins-config
              mountPath: /var/jenkins_home/config.xml
              subPath: config.xml
      volumes:
        - name: jenkins-home
          emptyDir: {}
        - name: jenkins-config
          configMap:
            name: jenkins-config

看起来詹金斯加载了默认的WARNING: Unable to move atomically, falling back to non-atomic move. java.nio.file.FileSystemException: /var/jenkins_home/atomic1870316694682040724tmp -> /var/jenkins_home/config.xml: Device or resource busy at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:396) at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262) at java.nio.file.Files.move(Files.java:1395) at hudson.util.AtomicFileWriter.commit(AtomicFileWriter.java:191) at hudson.XmlFile.write(XmlFile.java:198) at jenkins.model.Jenkins.save(Jenkins.java:3221) at jenkins.model.Jenkins.saveQuietly(Jenkins.java:3227) at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2505) at jenkins.model.Jenkins$16.run(Jenkins.java:3188) at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169) at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296) at jenkins.model.Jenkins$5.runTask(Jenkins.java:1066) at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214) at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Sep 15, 2018 10:06:23 PM hudson.util.AtomicFileWriter commit INFO: The target file /var/jenkins_home/config.xml was already existing Sep 15, 2018 10:06:23 PM hudson.util.AtomicFileWriter commit WARNING: Unable to move /var/jenkins_home/atomic1870316694682040724tmp to /var/jenkins_home/config.xml. Attempting to delete /var/jenkins_home/atomic1870316694682040724tmp and abandoning. Sep 15, 2018 10:06:23 PM jenkins.model.Jenkins saveQuietly WARNING: null java.nio.file.FileSystemException: /var/jenkins_home/config.xml: Device or resource busy at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:447) at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262) at java.nio.file.Files.move(Files.java:1395) at hudson.util.AtomicFileWriter.commit(AtomicFileWriter.java:206) at hudson.XmlFile.write(XmlFile.java:198) at jenkins.model.Jenkins.save(Jenkins.java:3221) at jenkins.model.Jenkins.saveQuietly(Jenkins.java:3227) at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2505) at jenkins.model.Jenkins$16.run(Jenkins.java:3188) at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169) at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296) at jenkins.model.Jenkins$5.runTask(Jenkins.java:1066) at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214) at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Suppressed: java.nio.file.FileSystemException: /var/jenkins_home/atomic1870316694682040724tmp -> /var/jenkins_home/config.xml: Device or resource busy at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:396) at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262) at java.nio.file.Files.move(Files.java:1395) at hudson.util.AtomicFileWriter.commit(AtomicFileWriter.java:191) ... 13 more 文件,然后用我发送的文件覆盖它,这让詹金斯吓坏了。

我可以制作我的Docker Image的这部分但是我想要使用K8S覆盖而不是在Image中制作文件。

关于如何在Jenkins启动时安全地引入config.xml文件的任何想法?

编辑

另一个尝试::

我甚至尝试过以下配置:

config.xml

但那会产生:

volumeMounts:
        - name: jenkins-home
          mountPath: /var/jenkins_home
          readOnly: false
  volumes:
    - name: jenkins-home
      configMap:
        name: jenkins-config
        items:
        - key: config.xml
          path: config.xml
jenkins kubernetes
1个回答
0
投票

你基本上将kubectl logs -n jenkins-pipeline jenkins-bc879c4df-m8nlc touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Read-only file system Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions? 安装在/var/jenkins_home/config.xml之上,jenkins无法写入它。试试这个:

/var/jenkins_home
© www.soinside.com 2019 - 2024. All rights reserved.