{"componentChunkName":"component---node-modules-gatsby-theme-blog-core-src-templates-post-query-js","path":"/validating-jenkinsfiles/","result":{"data":{"site":{"siteMetadata":{"title":"one melo a day","social":[{"name":"twitter","url":"https://twitter.com/melo0187"},{"name":"github","url":"https://github.com/melo0187"}]}},"blogPost":{"__typename":"MdxBlogPost","id":"2ebffa22-ddf3-57c7-8083-21e9ee293d30","excerpt":"How to use the Jenkins Pipeline Linter","body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"layout\": \"post\",\n  \"title\": \"What I wish I knew about Jenkinsfiles\",\n  \"author\": \"melo\",\n  \"date\": \"2018-11-18T17:47:55.000Z\",\n  \"categories\": [\"DevOps\", \"Jenkins\", \"Technical\"],\n  \"slug\": \"validating-jenkinsfiles\",\n  \"excerpt\": \"How to use the Jenkins Pipeline Linter\",\n  \"draft\": false,\n  \"meta_title\": \"What I wish I knew about Jenkinsfiles\"\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Every now and then I find myself in the situation where I want to set up a \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"https://jenkins.io/doc/book/pipeline/#overview\"\n  }), \"Declarative Jenkins Pipeline\"), \" for a new application. Usually I have access to plenty of other repositories and thus the opportunity to check out their Jenkinsfile, which is a great source of inspiration. However, sometimes the pipeline I need can\\u2019t simply be copy-pasted from bits and pieces of other pipelines I know.\", mdx(\"br\", {\n    parentName: \"p\"\n  }), \"\\n\", \"Normally this is when I start my journey on the bumpy road of trial and error, but recently I finally managed to level up my Jenkins Pipeline development tooling.\"), mdx(\"h2\", {\n    \"id\": \"the-jenkins-pipeline-linter\"\n  }, \"The Jenkins Pipeline Linter\"), mdx(\"p\", null, \"Obviously when getting into the situation where you don\\u2019t know how to achieve your goal, just copy-pasting stuff and going down the trial and error road indefinitely is neither efficient nor educational. Instead you take the time to educate yourself further and read the documentation, right?\", mdx(\"br\", {\n    parentName: \"p\"\n  }), \"\\n\", \"Well, when you do so for \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"https://jenkins.io/doc/book/pipeline/development/#linter\"\n  }), \"Jenkins Pipeline Development Tools\"), \" you might be more knowledgable, because you just found out that you can validate a Jenkinsfile upfront instead of just pushing the next change and crossing your fingers. And yet, you might be no step closer to improve on how you write and verify your pipeline. Reason being the fact that the two options described in the documentation have some prerequisites and chances are your Jenkins instance does not fulfil them. You either have the SSH service enabled on your Jenkins server for command line access or \\u201Canonymous read access\\u201D has been enabled on your Jenkins instance, since the documentation suggests that this is what you need to perform linting via HTTP POST using curl. Turns out the latter is not actually the case.\"), mdx(\"p\", null, \"If you can log in to Jenkins, you can use curl to let your Jenkins instance validate your Jenkinsfile, regardless of your server allowing \\u201Canonymous read access\\u201D!\", mdx(\"br\", {\n    parentName: \"p\"\n  }), \"\\n\", \"At the risk of stating the obvious: You can just use the documented curl command and add \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"-u <your_username>\"), \" as parameter. The command could look something like this:\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-shell\"\n  }), \"curl -X POST -u <your_username> \\\\\\n-F \\\"jenkinsfile=<Jenkinsfile\\\" \\\\\\n$JENKINS_URL/pipeline-model-converter/validate\\n\")), mdx(\"p\", null, \"I myself needed a friend to point this out to me.\"), mdx(\"h2\", {\n    \"id\": \"lint-before-wasting-your-jenkins-time\"\n  }, \"Lint before wasting your Jenkin\\u2019s time\"), mdx(\"p\", null, \"Now there are no excuses left, Not even that the curl command might be hard to remember! Just add it as a bash function, if you like:\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-shell\"\n  }), \"function jenkins-validate() {\\n  curl -X POST -u <your*username> -F \\\"jenkinsfile=<$1\\\" $JENKINS_URL/pipeline-model-converter/validate;\\n}\\n\")), mdx(\"p\", null, \"Now validating your Jenkinsfile is as easy as this:\", mdx(\"br\", {\n    parentName: \"p\"\n  }), \"\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"$ jenkins-validate Jenkinsfile\"), mdx(\"br\", {\n    parentName: \"p\"\n  }), \"\\n\", \"This way you finally have the confidence that your Jenkinsfile is at least syntactically correct \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"before\"), \" pushing a change to your repository to trigger the pipeline!\"));\n}\n;\nMDXContent.isMDXComponent = true;","slug":"/validating-jenkinsfiles/","title":"What I wish I knew about Jenkinsfiles","tags":[],"keywords":[],"date":"November 18, 2018"},"previous":{"__typename":"MdxBlogPost","id":"986539b7-38dc-5b5a-bc43-6502800aa2dc","excerpt":"Earlier this year I had the opportunity to develop an app in-house in a small team on our own terms. We went with  Flutter , which I enjoyed…","slug":"/dart-flutter-web/","title":"Exploration to use Dart across Web and Mobile","date":"October 06, 2018"},"next":{"__typename":"MdxBlogPost","id":"0af1db9e-d001-5f3c-a835-452760929071","excerpt":"I have been absent from my blog for quite a while now.\nOne of the reasons is that I really do not enjoy working with wordpress anymore.\nSo I…","slug":"/blog-reboot/","title":"Rebooting my blog","date":"November 03, 2019"}},"pageContext":{"isCreatedByStatefulCreatePages":false,"id":"2ebffa22-ddf3-57c7-8083-21e9ee293d30","previousId":"986539b7-38dc-5b5a-bc43-6502800aa2dc","nextId":"0af1db9e-d001-5f3c-a835-452760929071"}}}