跳转至

ci-generic 插件

这个插件可以基于本地或者远程的文件在 GitLab/GitHub 安装 CI 配置

用例

下面的配置文件展示的是"tool file"的内容。

关于更多关于DevStream的主配置、tool file、var file的信息,请阅读核心概念概览DevStream配置.

YAML
tools:
# name of the tool
- name: ci-generic
  # id of the tool instance
  instanceID: default
  # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool.
  dependsOn: [ ]
  # options for the plugin
  options:
    ci:
      # If your ci file is local or remote, you can set the this field to get ci file
      configLocation: JENKINSFILE_LOCATION
      # If you want to config ci in devstream, you can config configContents directly
      configContents:
        Jenkinsfile: JENKINSFILE_CONTENT
      # support jenkins-pipeline/gitlab-ci/github-actions for now
      type: jenkins-pipeline
    projectRepo:
      # scm common field
      branch: YOUR_REPO_BRANCH
      token: YOUR_REPO_SCM_TOKEN
      # you can directly use the url of repo
      url: YOUR_REPO_URL
      # or you can config detailed fields for this repo
      owner: YOUR_REPO_OWNER
      org: YOUR_REPO_ORG
      name: YOUR_REPO_NAME
      scmType: github
      # you can config this field if you are using self-host gitlab
      baseURL: YOUR_SELF_HOST_GITLAB_URL

注意事项:

  • projectRepo 配置字段用于表示代码仓库的配置信息,具体配置可查看SCM配置项
  • ci.configContentsci.configLocation 不能同时为空。
  • 如果你配置了 projectRepo.scmTypegithub,那 ci.type 就不能是 gitlab-ci
  • 如果你配置了 projectRepo.scmTypegitlab,那 ci.type 就不能是 github-actions

示例

使用本地的 Workflows 目录

YAML
tools:
- name: ci-generic
  instanceID: test-github
  options:
    ci:
      configLocation: workflows
      type: github
    projectRepo:
      owner: devstream
      org: ""
      name: test-repo
      branch: main
      scmType: github

这个配置将会把本地当前运行环境下的 workflows 目录放置于 GitHub 的 .github/workflows 目录。

使用 HTTP 获取远程的CI文件

YAML
tools:
- name: ci-generic
  instanceID: test-gitlab
  options:
    ci:
      configLocation : https://raw.githubusercontent.com/DeekshithSN/Jenkinsfile/inputTest/Jenkinsfile
      type: jenkins
    projectRepo:
      owner: root
      org: ""
      name: test-repo
      branch: main
      scmType: gitlab
      baseURL: http://127.0.0.1:30000

这个配置将会把URL 中的 Jenkinsfile 文件置于 GitLab 的仓库。

使用Github仓库中的CI文件

YAML
tools:
- name: ci-generic
  instanceID: test-gitlab
  options:
    ci:
      configLocation : git@github.com:devstream-io/devstream.git//staging/dtm-jenkins-pipeline-example/general
      type: jenkins
    projectRepo:
      owner: root
      org: ""
      name: test-repo
      branch: main
      scmType: gitlab
      baseURL: http://127.0.0.1:30000

这个配置将会搜索devstream 仓库下的staging/dtm-jenkins-pipeline-example/general 目录,获取到目录下的 Jenkinsfile,置于 gitlab 仓库内。

在Devstream中直接配置CI文件

YAML
tools:
- name: ci-generic
  instanceID: test-gitlab
  options:
    ci:
      configContents:
        pr.yaml: |
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      projectRepo:
        owner: test-user
        org: ""
        name: test-repo
        branch: main
        scmType: github

这个配置将会在用户的Github仓库test-user/test-repo下创建.github/workflows/pr.yaml文件。