{"id":830,"date":"2019-03-05T18:30:17","date_gmt":"2019-03-05T15:30:17","guid":{"rendered":"https:\/\/artem.services\/?p=830"},"modified":"2019-03-12T11:47:04","modified_gmt":"2019-03-12T08:47:04","slug":"jenkins-dsl-multibranch-pipeline-build","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=830","title":{"rendered":"Jenkins &#8212; DSL Multibranch Pipeline \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Seed Job&#8217;\u043e\u043c"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-819 aligncenter\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo.png\" alt=\"\" width=\"1280\" height=\"412\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo.png 1280w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-300x97.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-768x247.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-1024x330.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2019\/02\/Jenkins-Logo-954x307.png 954w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0435 <strong>groovy<\/strong> \u0444\u0430\u0439\u043b\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u0438\u043c\u0435\u043d\u0435\u043c &quot;<strong>utilities<\/strong>&quot; \u0438 \u0432 \u043d\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b &quot;<strong>BitbucketMultibranch.groovy<\/strong>&quot; \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\npackage utilities\r\n\r\nimport javaposse.jobdsl.dsl.DslFactory\r\n\r\nclass BitbucketMultibranch {\r\n\r\n    String name\r\n    String description\r\n    String displayName\r\n    String serverUrl\r\n    String repoOwner\r\n    String repository\r\n    String credentialsId\r\n    String includeBranches\r\n    String excludeBranches\r\n\r\n\tvoid build(DslFactory dslFactory) {\r\n\t    def job = dslFactory.multibranchPipelineJob(name) {\r\n\t        description(description)\r\n\t        displayName(displayName)\r\n\t        branchSources {\r\n\t            branchSource {\r\n\t                source {\r\n\t                    bitbucket {\r\n\t                        serverUrl(serverUrl)\r\n\t                        repoOwner(repoOwner)\r\n\t                        repository(repository)\r\n\t                        credentialsId(credentialsId)\r\n\t                        traits {\r\n\t                            headWildcardFilter {\r\n\t                                excludes(excludeBranches)\r\n\t                                includes(includeBranches)\r\n\t                            }\r\n\t                        }\r\n\t                    }\r\n\t                }\r\n\t            }\r\n\t        }\r\n\t        configure {\r\n\t          \tdef traits = it \/ sources \/ data \/ 'jenkins.branch.BranchSource' \/ source \/ traits\r\n\t          \ttraits &lt;&lt; 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {\r\n\t            \tstrategyId(3) \/\/ detect all branches\r\n\t          \t}\r\n\t        }\r\n        \tfactory {\r\n\t            workflowBranchProjectFactory {\r\n\t                scriptPath('.jenkins\/Jenkinsfile')\r\n\t            }\r\n\t        }\r\n\t        orphanedItemStrategy {\r\n\t            discardOldItems {\r\n\t                numToKeep(15)\r\n\t            }\r\n\t        }\r\n\t    }\r\n\t}\r\n}\r\n<\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <strong>Item<\/strong>&#39;\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u043a\u043e\u0440\u043d\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <strong>groovy<\/strong>, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 <strong>Seed Job<\/strong> \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043b.<\/p>\n<p><!--more--><\/p>\n<h4>artem-dsl.groovy<\/h4>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\nimport utilities.BitbucketMultibranch\r\n\r\ndef multiPipeline = new BitbucketMultibranch(\r\n    description: 'Just try make world better',\r\n    name: 'Artem-DSL',\r\n    displayName: 'Artem-DSL',\r\n    serverUrl: 'https:\/\/git.artem.services',\r\n    repoOwner: &quot;dev&quot;,\r\n    repository: &quot;artem-dls&quot;,\r\n    credentialsId: 'svc-bitbucket',\r\n    includeBranches: 'development staging master',\r\n    excludeBranches: ''\r\n).build(this)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4>\u0421\u0431\u043e\u0440\u043a\u0430 \u0434\u043b\u044f GitHub&#8217;\u0430.<\/h4>\n<h4>GitHubMultibranch.groovy:<\/h4>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\npackage utilities\r\n\r\nimport javaposse.jobdsl.dsl.DslFactory\r\n\r\nclass GithubMultibranch {\r\n\r\n    String name\r\n    String description\r\n    String displayName\r\n    String repositoryOwner\r\n    String repositoryName\r\n    String credentials\r\n    String includeBranches\r\n    String excludeBranches\r\n\r\n\r\n\tvoid build(DslFactory dslFactory) {\r\n\t    def job = dslFactory.multibranchPipelineJob(name) {\r\n\t        description(description)\r\n\t        displayName(displayName)\r\n\t\t    branchSources {\r\n\t\t        github {\r\n\t\t            scanCredentialsId(credentials)\r\n\t\t            repoOwner(repositoryOwner)\r\n\t\t            repository(repositoryName)\r\n\t\t            includes(includeBranches)\r\n\t\t            excludes(excludeBranches)\r\n\t\t        }\r\n\t\t    }\r\n\t\t    factory {\r\n\t\t        workflowBranchProjectFactory {\r\n\t\t            scriptPath('.jenkins\/Jenkinsfile')\r\n\t\t        }\r\n\t\t    }\r\n\t\t    orphanedItemStrategy {\r\n\t\t        discardOldItems {\r\n\t\t            numToKeep(15)\r\n\t\t        }\r\n\t\t    }\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<h4>artem-github.groovy:<\/h4>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\nimport utilities.GithubMultibranch\r\n\r\n\r\ndef multiPipeline = new GithubMultibranch(\r\n    description: 'Just try make world better',\r\n    name: 'Github-Test',\r\n    displayName: 'Github-Test',\r\n    repositoryOwner: &quot;artem&quot;,\r\n    repositoryName: &quot;dsl-test&quot;,\r\n    credentials: 'artem-github',\r\n    includeBranches: 'development staging master',\r\n    excludeBranches: ''\r\n).build(this)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0435 groovy \u0444\u0430\u0439\u043b\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0441 \u0438\u043c\u0435\u043d\u0435\u043c &quot;utilities&quot; \u0438 \u0432 \u043d\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b &quot;BitbucketMultibranch.groovy&quot; \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c: \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Item&#39;\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432 \u043a\u043e\u0440\u043d\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c groovy, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 Seed Job \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043b.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[37],"tags":[579,575,39,573,577,125,571,583],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/830"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=830"}],"version-history":[{"count":7,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/830\/revisions"}],"predecessor-version":[{"id":850,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/830\/revisions\/850"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}