首页 > 解决方案 > 从文件中获取作业 DSL 脚本时。如何在 jenkins helm chart jcasc 部分以及格式中完成此操作?

问题描述

到目前为止我的理解: 这是有道理的,我传入一个文件而不是硬编码脚本值

jobs:
  - script: >
      multibranchPipelineJob('configuration-as-code') {
          branchSources {
              git {
                  id = 'configuration-as-code'
                  remote('https://github.com/jenkinsci/configuration-as-code-plugin.git')
              }
          }
      }

jobs:
  - file: ./jobdsl/job.groovy

当前设置:在 jcasc 部分下的 jenkins helm values 文件中,我有以下内容。这很好,它与我未在此处显示的其他配置一起使用(与此讨论无关)

   JCasC:
      defaultConfig: true
      configScripts:
        pipeline-job: |
          jobs:
            - script: >
                multibranchPipelineJob('testrepo') {
                  branchSources {
                    git {
                      id('testrepo')
                      credentialsId('bitbucketv1')
                      remote('https://bitbucket.org/repo/test.git')
                      includes("master develop")
                      excludes("")
                    }
                  }

问题:

如何获取我的代码并将其作为文件传递,例如“-file: ./jobdsl/job.groovy”。我在我的 jenkins helm 文件夹中创建了一个名为 jobdsl 的文件夹,并在开始时添加了带有 multibranchpipelinejob 代码片段的 job.groovy。但是我收到一条错误消息,说文件不存在。

我是否需要先创建一个配置映射并将此文件加载到 jenkins 中?或者有没有办法将文件从本地传递到上面我的掌舵图表片段中的 jcasc 脚本?另外,job.groovy 的正确格式是什么?它包括 -script: > 部分还是仅来自 multibranchpipelinejob 和向下?

标签: jenkinskubernetes-helmjcasc

解决方案


推荐阅读