{"id":883,"date":"2019-03-06T16:56:32","date_gmt":"2019-03-06T13:56:32","guid":{"rendered":"https:\/\/artem.services\/?p=839"},"modified":"2019-03-12T17:50:54","modified_gmt":"2019-03-12T14:50:54","slug":"jenkins-dsl-pipeline-build-2","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=883&lang=en","title":{"rendered":"Jenkins &#8212; DSL Pipeline creating by Seed Job"},"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><span class=\"tlid-translation translation\"><span class=\"\" title=\"\">In the repository where the future <strong>groovy<\/strong> files will be stored, create a directory called &quot;<strong>utilities<\/strong>&quot; and create the file &quot;<strong>GithubPipeline.groovy<\/strong>&quot; in it with the following contents:<\/span><\/span><\/p>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\npackage utilities\r\n\r\nimport javaposse.jobdsl.dsl.DslFactory\r\n\r\nclass GithubPipeline {\r\n\r\n    String name\r\n    String description\r\n    String displayName\r\n    String branchesName\r\n    String urlRepo\r\n    String credentialsId\r\n\r\n\r\n\tvoid build(DslFactory dslFactory) {\r\n\t    def job = dslFactory.pipelineJob(name) {\r\n\t        description(description)\r\n\t        displayName(displayName)\r\n\t\t\tdefinition {\r\n\t\t        cpsScm {\r\n\t\t            scm {\r\n\t\t                git {\r\n\t\t                    branches(branchesName)\r\n\t\t                    remote {\r\n\t\t                        url(urlRepo)\r\n                        \t\tcredentials(credentialsId)\r\n\t\t                    }\r\n\t\t                }\r\n\t\t                scriptPath('Jenkinsfile')\r\n\t\t                lightweight(true)\r\n\t\t            }\r\n\t\t        }\r\n\t\t    }\r\n\t\t    parameters {\r\n\t\t        choiceParam ('Environment', ['staging', 'production', 'staging-without-cache'], 'Please choice env to build')\r\n\t\t    }\r\n\t\t    triggers {\r\n\t\t        bitbucketPush()\r\n\t\t    }\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><span class=\"tlid-translation translation\"><span class=\"\" title=\"\">Now, to create an <strong>Item<\/strong>, it is enough to create a file with the <strong>groovy<\/strong> extension in the root of the repository, so that it can be processed by <strong>Seed Job<\/strong>.<\/span><\/span><\/p>\n<p><!--more--><\/p>\n<h4>pipeline-dsl.groovy<\/h4>\n<pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\r\nimport utilities.GithubPipeline\r\n\r\ndef pipeline = new GithubPipeline(\r\n    description: 'Pipeline DSL',\r\n    name: 'pipeline-dsl',\r\n    displayName: 'Pipeline DSL',\r\n    branchesName: '*\/pipeline-dsl',\r\n    urlRepo: 'git@github.com:artem\/devops.git',\r\n    credentialsId: 'artem-github'\r\n).build(this)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In the repository where the future groovy files will be stored, create a directory called &quot;utilities&quot; and create the file &quot;GithubPipeline.groovy&quot; in it with the following contents: Now, to create an Item, it is enough to create a file with the groovy extension in the root of the repository, so that it can be processed &hellip; <a href=\"https:\/\/artem.services\/?p=883&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;Jenkins &#8212; DSL Pipeline creating by Seed Job&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[613],"tags":[635,615,627,617,641,639],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/883"}],"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=883"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":885,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions\/885"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}