简体   繁体   English

如何为詹金斯管道声明定义工作区体积

[英]How to define workspace volume for jenkins pipeline declarative

I am trying to setup declarative pipeline where I would like to persiste workspace as volume claim so large git checkout can be faster.我正在尝试设置声明性管道,我希望将工作区作为容量声明持久化,以便大型 git checkout 可以更快。 Based on doc there are options workspaceVolume and persistentVolumeClaimWorkspaceVolume but I am not able to make it work - jenkins always does following:基于doc有选项workspaceVolumepersistentVolumeClaimWorkspaceVolume但我无法使其工作 - jenkins 总是执行以下操作:

volumeMounts:
 - mountPath: "/home/jenkins/agent"
   name: "workspace-volume"
   readOnly: false
volumes:
  - emptyDir: {}
    name: "workspace-volume"

Try something like尝试类似的东西

podTemplate(
    containers: [
        containerTemplate(name: 'tree', image: 'iankoulski/tree', ttyEnabled: true, command: 'cat')
    ], 
    workspaceVolume: persistentVolumeClaimWorkspaceVolume(claimName: 'workspace', readOnly: false),
) {
    node(POD_LABEL) {
        stage('read workspace') {
            checkout scm
            container('tree') {
                sh 'env'
                sh 'tree'
                sh 'test -f old-env.txt && cat old-env.txt'
                sh 'env > old-env.txt'
            }
        }
    }
}

Here is an example for declarative pipeline:这是声明性管道的示例:

pipeline {
agent {
    kubernetes {
        yamlFile 'jenkins/pv-pod.yaml'
        workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: 'workspace', readOnly: false)
    }
}

If you post your jenkins deployment then I might help in that.如果您发布 jenkins 部署,那么我可能会提供帮助。

Mean while you can visit this yaml that I used and worked very well for me.同时,您可以访问我使用的这个 yaml,它对我来说效果很好。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      containers:
      - name: jenkins
        image: jenkins:2.32.2
        ports:
        - containerPort: 8080
        volumeMounts:
          - name: jenkins-home
            mountPath: /var/jenkins_home
      volumes:
        - name: jenkins-home
          emptyDir: {}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins声明性管道:如何在docker容器中挂载与工作空间关联的临时卷? - Jenkins Declarative Pipeline: How can I mount a temporary volume associated with the workspace in a docker container? Jenkins声明式管道:如何定义不稳定状态 - Jenkins declarative Pipeline: How to define UNSTABLE state 如何通过编写 jenkins 声明性管道将 jenkins 构建到工作区中 - How to save jenkins builds into workspace by writing jenkins declarative pipeline 在Jenkins声明式管道中定义全局Ant工具 - Define a global Ant tool in a Jenkins Declarative Pipeline 在 Jenkins 声明性管道的参数中定义凭证参数? - Define credential parameter in parameters in Jenkins declarative pipeline? 在 Jenkins 声明性管道参数中使用 Jenkins WORKSPACE 环境变量 - Use Jenkins WORKSPACE environment variable in Jenkins declarative pipeline parameter 如何在继承自管道共享库的声明性 jenkins 管道中定义其他参数? - How can I define additional parameters in a declarative jenkins pipeline who inherit from a pipeline shared library? Jenkins声明式管道为并行构建创建自定义工作区 - Jenkins declarative pipeline create custom workspace for parallel builds 如何将 jenkins 脚本化管道转换为声明性管道 - how to convert jenkins scripted pipeline to declarative pipeline 在 Jenkins 声明性管道中将存储库根添加为 Docker 卷 - Add the repo root as a Docker volume in a Jenkins declarative pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM