ci-generic 插件

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

用例

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

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

YAML

  1. tools:
  2. # name of the tool
  3. - name: ci-generic
  4. # id of the tool instance
  5. instanceID: default
  6. # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool.
  7. dependsOn: [ ]
  8. # options for the plugin
  9. options:
  10. ci:
  11. # If your ci file is local or remote, you can set the this field to get ci file
  12. configLocation: JENKINSFILE_LOCATION
  13. # If you want to config ci in devstream, you can config configContents directly
  14. configContents:
  15. Jenkinsfile: JENKINSFILE_CONTENT
  16. # support jenkins-pipeline/gitlab-ci/github-actions for now
  17. type: jenkins-pipeline
  18. projectRepo:
  19. # scm common field
  20. branch: YOUR_REPO_BRANCH
  21. token: YOUR_REPO_SCM_TOKEN
  22. # you can directly use the url of repo
  23. url: YOUR_REPO_URL
  24. # or you can config detailed fields for this repo
  25. owner: YOUR_REPO_OWNER
  26. org: YOUR_REPO_ORG
  27. name: YOUR_REPO_NAME
  28. scmType: github
  29. # you can config this field if you are using self-host gitlab
  30. 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

  1. tools:
  2. - name: ci-generic
  3. instanceID: test-github
  4. options:
  5. ci:
  6. configLocation: workflows
  7. type: github
  8. projectRepo:
  9. owner: devstream
  10. org: ""
  11. name: test-repo
  12. branch: main
  13. scmType: github

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

使用 HTTP 获取远程的CI文件

YAML

  1. tools:
  2. - name: ci-generic
  3. instanceID: test-gitlab
  4. options:
  5. ci:
  6. configLocation : https://raw.githubusercontent.com/DeekshithSN/Jenkinsfile/inputTest/Jenkinsfile
  7. type: jenkins
  8. projectRepo:
  9. owner: root
  10. org: ""
  11. name: test-repo
  12. branch: main
  13. scmType: gitlab
  14. baseURL: http://127.0.0.1:30000

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

使用Github仓库中的CI文件

YAML

  1. tools:
  2. - name: ci-generic
  3. instanceID: test-gitlab
  4. options:
  5. ci:
  6. configLocation : git@github.com:devstream-io/devstream.git//staging/dtm-jenkins-pipeline-example/general
  7. type: jenkins
  8. projectRepo:
  9. owner: root
  10. org: ""
  11. name: test-repo
  12. branch: main
  13. scmType: gitlab
  14. baseURL: http://127.0.0.1:30000

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

在Devstream中直接配置CI文件

YAML

  1. tools:
  2. - name: ci-generic
  3. instanceID: test-gitlab
  4. options:
  5. ci:
  6. configContents:
  7. pr.yaml: |
  8. name: GitHub Actions Demo
  9. run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
  10. on: [push]
  11. jobs:
  12. Explore-GitHub-Actions:
  13. runs-on: ubuntu-latest
  14. steps:
  15. - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
  16. projectRepo:
  17. owner: test-user
  18. org: ""
  19. name: test-repo
  20. branch: main
  21. scmType: github

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