Jenkinsfile从库调用管道

jdg4fx2g  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(162)

我有两个仓库,除了代码开头的4个变量的值之外,它们的管道都是一样的。存储库用于生产和开发环境。
我想把管道写成一个库,然后从存储库调用它,把变量作为参数传递。有可能吗?
我试着这样做图书馆:pipelineDeployBq2bq.groovy

  1. def call(Map variable1, Map variable2, Map variable3, Map variable4){
  2. pipeline{
  3. ...
  4. }
  5. }

字符串
然后从仓库中的Jenkinsfile调用如下:

  1. pipeline {
  2. agent {
  3. kubernetes {
  4. label "xxxxxx"
  5. yamlFile 'xxxxxx'
  6. }
  7. }
  8. environment {
  9. PROJECT_TYPE = xxxxxxx
  10. }
  11. stages {
  12. stage('Stage 1') {
  13. steps {
  14. pipelineDeployBq2bq(prfBuckets, environmentProjects, pubSubByEnvironment, composerTags)
  15. }
  16. }
  17. }//End stages
  18. }//End pipelines


但我得到了这样的错误

  1. Only one pipeline { ... } block can be executed in a single run.

gudnpqoy

gudnpqoy1#

这里的主要问题是在同一个声明性管道中调用pipeline两次(根据定义,这是不可能的)。一个解决方案,如果您的管道包含多个阶段(它的作品完全罚款只有一个阶段太)是这样做

  1. def call(Map variable1, Map variable2, Map variable3, Map variable4){
  2. stage('Stage1'){
  3. steps{...
  4. }
  5. }
  6. stage('StageX'){
  7. steps{...
  8. }
  9. }
  10. }

字符串
在你的管道中这样称呼它:

  1. pipeline{ //all your setup stuff
  2. stages {
  3. pipelineDeployBq2bq(prfBuckets,environmentProjects,pubSubByEnvironment, composerTags)
  4. stage('Stage 2'){
  5. ...
  6. }
  7. }//End of stages
  8. }//End of pipeline

展开查看全部

相关问题