jenkins - Creating pipeline code in MultiBranchPipelineJob - Stack Overflow

I have a multibranchpipeline job but I don't want to run the code in the Jenkinsfile in the repo.

I have a multibranchpipeline job but I don't want to run the code in the Jenkinsfile in the repo. Instead I want to run a short pipeline script defined in the dsl script. What I have in my mind looks like this

multibranchPipelineJob('my-multibranch-pipeline') {
    displayName('My Multi-Branch Pipeline')
    description('Multi-Branch Pipeline con Workflow Pipeline Project Factory')

    branchSources {
        git {
            id('my-git-source')
            remote('.git')
            credentialsId('my-git-credentials')
            includes('*')
        }
    }

    factory {
        pipelineFactory {
            script("""
                pipeline {
                    agent any
                    stages {
                        stage('Checkout') {
                            steps {
                                echo 'hello world'
                            }
                        }                   
                    }
                }
            """)
        }
    }
}

pipelineFactory don't exist, it's just to show you what i want to do. My question is, how can I actually implement this? I can also use scripts in my shared library if there is chance to do so.

I have a multibranchpipeline job but I don't want to run the code in the Jenkinsfile in the repo. Instead I want to run a short pipeline script defined in the dsl script. What I have in my mind looks like this

multibranchPipelineJob('my-multibranch-pipeline') {
    displayName('My Multi-Branch Pipeline')
    description('Multi-Branch Pipeline con Workflow Pipeline Project Factory')

    branchSources {
        git {
            id('my-git-source')
            remote('https://github/op/myrepo.git')
            credentialsId('my-git-credentials')
            includes('*')
        }
    }

    factory {
        pipelineFactory {
            script("""
                pipeline {
                    agent any
                    stages {
                        stage('Checkout') {
                            steps {
                                echo 'hello world'
                            }
                        }                   
                    }
                }
            """)
        }
    }
}

pipelineFactory don't exist, it's just to show you what i want to do. My question is, how can I actually implement this? I can also use scripts in my shared library if there is chance to do so.

Share asked Mar 7 at 16:55 Simone GhellerSimone Gheller 231 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

As far as I remember, it's not possible with multibranch pipeline, as its idea is to take the Jenkinsfile from the repository (because it might differ between different branches). But it might be possible with pipelineJob.

With multibranchPipelineJob you can only set the path to the Jenkinsfile within your myrepo.git repository like this (a full example could be found in Setting pipeline description in declarative Jenkinsfile):

// ...
  factory {
    workflowBranchProjectFactory {
      scriptPath("path/to/Jenkinsfile")
    }
  }
// ...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744917020a4600897.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信