Last active
April 10, 2023 10:57
-
-
Save SansGuidon/2958ba47630a176733e0136b42557284 to your computer and use it in GitHub Desktop.
Revisions
-
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ This gist shows how you can validate Jenkinsfile within Vim :-) but if you don't use Vim, you should be able to use it in a terminal or adapt it to your needs anyway, you can even convert it to a bash function ;-) It's inspired by the official documentation https://www.jenkins.io/doc/book/pipeline/development/#linter ## Validator script * Expose your jenkins credentials and instance URLs somehow (environment variables) * `JENKINS_URL` -
SansGuidon revised this gist
Jun 24, 2020 . No changes.There are no files selected for viewing
-
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ This gist shows how you can validate Jenkinsfile within Vim :-) but if you don't `checkci`, `checkci Jenkinsfile.acceptance`, ... ## Vim Integration * Install https://github.com/dense-analysis/ale via the vim plugin manager of your choice, or manually... I suggest you start at https://vimawesome.com/plugin/ale ;) * Update your `~/.vimrc` with the proposed config * Create `~/.vim/ale_linters/Jenkinsfile/checkci.vim` with the proposed content -
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,11 +9,8 @@ This gist shows how you can validate Jenkinsfile within Vim :-) but if you don't * `JENKINS_SECRET` (password, or user token...) * Create somewhere (`~/scripts/checkci.sh` ?) a script with the proposed content in this gist. * make it executable `chmod +x ~/.scripts/checkci.sh` * create a symbolic link to it. example : `ln -snf ~/.scripts/checkci.sh /usr/local/bin/checkci` * It should be enough to allow you to validate Jenkinsfile via the terminal. example: `checkci`, `checkci Jenkinsfile.acceptance`, ... ## Vim Integration -
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,9 @@ This gist shows how you can validate Jenkinsfile within Vim :-) but if you don't ``` ln -snf ~/.scripts/checkci.sh /usr/local/bin/checkci ``` * It should be enough to allow you to validate Jenkinsfile via the terminal, example: `checkci`, `checkci Jenkinsfile.acceptance`, ... ## Vim Integration * Install https://github.com/dense-analysis/ale via the vim plugin manager of your choice, or manually... * Update your `~/.vimrc` with the proposed config -
SansGuidon revised this gist
Jun 24, 2020 . No changes.There are no files selected for viewing
-
SansGuidon revised this gist
Jun 24, 2020 . 2 changed files with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ " ~/.vimrc " ... " Check syntax in Vim asynchronously and fix files, with Language Server Protocol (LSP) support Plugin 'dense-analysis/ale' " ... " dense-analysis/ale options let g:ale_history_log_output = 1 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,6 @@ #... # expose those variables here or anything else export JENKINS_USERNAME="" export JENKINS_URL="https://jenkins.mycompany.com" export JENKINS_SECRET="<API_TOKEN_HERE>" #... -
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,4 +22,4 @@ ln -snf ~/.scripts/checkci.sh /usr/local/bin/checkci  ## Demo (CLI)  -
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,5 +18,8 @@ ln -snf ~/.scripts/checkci.sh /usr/local/bin/checkci * Update your `~/.vimrc` with the proposed config * Create `~/.vim/ale_linters/Jenkinsfile/checkci.vim` with the proposed content ## Demo (Vim Integration)  ## Demo (CLI) [!Demo (CLI)](https://i.imgur.com/oU4cY6T.png) -
SansGuidon revised this gist
Jun 24, 2020 . 1 changed file with 13 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,22 @@ # Introduction This gist shows how you can validate Jenkinsfile within Vim :-) but if you don't use Vim, you should be able to use it in a terminal or adapt it to your needs anyway, you can even convert it to a bash function ;-) ## Validator script * Expose your jenkins credentials and instance URLs somehow (environment variables) * `JENKINS_URL` * `JENKINS_USERNAME` * `JENKINS_SECRET` (password, or user token...) * Create somewhere (`~/scripts/checkci.sh` ?) a script with the proposed content in this gist. * make it executable `chmod +x ~/.scripts/checkci.sh` * create a symbolic link to it. Example : ``` ln -snf ~/.scripts/checkci.sh /usr/local/bin/checkci ``` ## Vim Integration * Install https://github.com/dense-analysis/ale via the vim plugin manager of your choice, or manually... * Update your `~/.vimrc` with the proposed config * Create `~/.vim/ale_linters/Jenkinsfile/checkci.vim` with the proposed content ## Demo  -
SansGuidon created this gist
Jun 24, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ " ~/.vimrc " ... " Check syntax in Vim asynchronously and fix files, with Language Server Protocol (LSP) support Plugin 'dense-analysis/ale' " ... " dense-analysis/ale options let g:ale_history_log_output = 1 let g:ale_use_global_executables = 1 let g:ale_fix_on_save = 1 let g:ale_completion_enabled = 1 let g:ale_open_list = 1 let g:ale_fixers = { \ '*': ['remove_trailing_lines', 'trim_whitespace'], \ 'Jenkinsfile': ['checkci'], \} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ #!/usr/bin/env bash # ~/.zshrc #... # expose those variables here or anything else export JENKINS_USERNAME="" export JENKINS_URL="" export JENKINS_SECRET="" #... This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ * Install https://github.com/dense-analysis/ale via the vim plugin manager of your choice, or manually... * Update your `~/.vimrc` with the proposed config * Expose your jenkins credentials and instance URLs somehow (environment variables) * `JENKINS_URL` * `JENKINS_USERNAME` * `JENKINS_SECRET` (password, or user token...) * Create `~/.vim/ale_linters/Jenkinsfile/checkci.vim` with the proposed content * Create somewhere (`~/scripts/checkci.sh` ?) a script with the proposed content in this gist. * make it executable `chmod +x ~/.scripts/checkci.sh` * create a symbolic link to it. Example : ``` ln -snf ~/.scripts/checkci.sh /usr/local/bin/checkci ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ #!/usr/bin/env bash # ~/.scripts/checkci.sh #... # expose those variables (in your ~/.zshrc, your (bash) profile, or anywhere you prefer... #export JENKINS_USERNAME="" #export JENKINS_URL="" #export JENKINS_SECRET="" #... function _checkci() { local jenkinsfile="${1:-Jenkinsfile}" curl --user "$JENKINS_USERNAME:$JENKINS_SECRET" -X POST -F "jenkinsfile=<$jenkinsfile" "$JENKINS_URL/pipeline-model-converter/validate" } _checkci "$*" exit 0 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ " ~/.vim/ale_linters/Jenkinsfile/checkci.vim call ale#linter#Define('Jenkinsfile', { \ 'name': 'checkci', \ 'executable': 'checkci', \ 'command': 'checkci', \ 'callback': 'ale_linters#Jenkinsfile#checkci#HandleJenkinsValidator', \}) function! ale_linters#Jenkinsfile#checkci#HandleJenkinsValidator(buffer, lines) abort " Regular expression to match messages: " They look like: " WorkflowScript: 7: Expected a step @ line 7, column 17. let l:pattern = '\v^WorkflowScript: (\d+): (.*) \@ line (\d+), column (\d+)\.(\_.*)$' " For each match, update the l:output list: let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) let l:code = l:match[5] call add(l:output, { \ 'lnum': l:match[3] + 0, \ 'col': l:match[4] + 0, \ 'text': l:code . ': ' . l:match[2], \}) endfor return l:output endfunction