├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .ruby-version ├── .tool-versions ├── .vim-version ├── Flavorfile.lock ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── doc └── jenkins.txt ├── plugin └── jenkins.vim └── test └── jenkins.vim /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | schedule: 9 | - cron: 0 0 * * * 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up Ruby 17 | uses: ruby/setup-ruby@v1 18 | with: 19 | bundler-cache: true 20 | - name: Get local Vim version 21 | run: echo "local_vim_version=$(<.vim-version)" >>$GITHUB_ENV 22 | - name: Set up Vim 23 | uses: rhysd/action-setup-vim@v1 24 | with: 25 | # use nightly for scheduled runs and use .vim-version for CI push-based runs 26 | # version: ${{ github.event_name == 'schedule' && 'nightly' || env.local_vim_version }} 27 | version: ${{ env.local_vim_version }} 28 | - name: Run tests 29 | # 2>&1 required to avoid interleaved stdout and stderr in log. 30 | run: rake ci 2>&1 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vim-flavor 2 | /Flavorfile.lock 3 | /Jenkinsfile 4 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.0.3 2 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 3.0.3 2 | -------------------------------------------------------------------------------- /.vim-version: -------------------------------------------------------------------------------- 1 | v8.2.3786 2 | -------------------------------------------------------------------------------- /Flavorfile.lock: -------------------------------------------------------------------------------- 1 | kana/vim-vspec (v1.9.2) 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | group :test do 4 | gem 'rake', '12.3.3' 5 | gem 'rspec' 6 | 7 | # definitely not actually using this, but instead https://github.com/kana/vim-vspec/blob/vim9/TUTORIAL-CI.md 8 | gem 'vimrunner' # http://mudge.name/2012/04/18/testing-vim-plugins-on-travis-ci-with-rspec-and-vimrunner.html 9 | 10 | gem 'vim-flavor', '~> 4.0' 11 | end 12 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | diff-lcs (1.2.5) 5 | parslet (2.0.0) 6 | pastel (0.8.0) 7 | tty-color (~> 0.5) 8 | rake (12.3.3) 9 | rspec (2.14.1) 10 | rspec-core (~> 2.14.0) 11 | rspec-expectations (~> 2.14.0) 12 | rspec-mocks (~> 2.14.0) 13 | rspec-core (2.14.8) 14 | rspec-expectations (2.14.5) 15 | diff-lcs (>= 1.1.3, < 2.0) 16 | rspec-mocks (2.14.6) 17 | thor (1.1.0) 18 | tty-color (0.6.0) 19 | vim-flavor (4.0.1) 20 | parslet (>= 1.8, < 3.0) 21 | pastel (~> 0.7) 22 | thor (>= 0.20, < 2.0) 23 | vimrunner (0.3.1) 24 | 25 | PLATFORMS 26 | ruby 27 | 28 | DEPENDENCIES 29 | rake (= 12.3.3) 30 | rspec 31 | vim-flavor (~> 4.0) 32 | vimrunner 33 | 34 | BUNDLED WITH 35 | 2.2.32 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jenkins.vim - [![CI](https://github.com/burnettk/vim-jenkins/actions/workflows/ci.yml/badge.svg)](https://github.com/burnettk/vim-jenkins/actions/workflows/ci.yml) 2 | 3 | Do you use Jenkins? Do you use vim? Do you like cute features? 4 | 5 | ## Setup 6 | 7 | You need to be using Jenkinsfiles for any of this to work. If you don't already 8 | use them, stop clawing your eyes out by typing and clicking around in your CI 9 | system and put your build plan configurations into source control for crying out 10 | loud. 11 | 12 | After you install via the instructions below, in your .vimrc, configure your 13 | jenkins url and some credentials that can get you in there: 14 | 15 | let g:jenkins_url = 'https://jenkins.example.com' 16 | let g:jenkins_username = 'ci' 17 | let g:jenkins_password = 'ci' 18 | 19 | ## Features 20 | 21 | ### Find current build status 22 | 23 | In your Jenkinfile, add a comment like this: 24 | 25 | // BUILD_PLAN_PATH: /view/Sweetapps/job/hot-app/job/master 26 | 27 | Then, call JenkinsShowLastBuildResult by using the "jenkins build" shortcut: 28 | 29 | jb 30 | 31 | ### Validate Jenkinsfile 32 | 33 | Call JenkinsValidateJenkinsFile by using the "run Jenkinsfile" shortcut: 34 | 35 | rj 36 | 37 | Major props to the Jenkins guys for providing this killer feature via the API. 38 | 39 | Thanks to [jasquat][jasquat] for collaborating on the initial version of this. 40 | 41 | ## Installation 42 | 43 | * Using [Pathogen][pathogen], run the following commands: 44 | 45 | % cd ~/.vim/bundle 46 | % git clone git://github.com/burnettk/vim-jenkins.git 47 | 48 | * Using [Vundle][vundle], add the following to your `vimrc` and then run 49 | `:PluginInstall` 50 | 51 | Plugin 'burnettk/vim-jenkins' 52 | 53 | Once help tags have been generated, you can view the manual with 54 | `:help jenkins`. 55 | 56 | ## Self-Promotion 57 | 58 | Like vim-jenkins.vim? Star the repository on [GitHub][project]. And if you're 59 | feeling especially charitable, follow [me][mysite] on [Twitter][mytwitter] and 60 | [GitHub][mygithub]. 61 | 62 | ## Contributors 63 | 64 | [burnettk][burnettk] 65 | [iborovskyi][iborovskyi] 66 | [jasquat][jasquat] 67 | 68 | ## License 69 | 70 | Copyright (c) Kevin Burnett. Distributed under the same terms as Vim itself. 71 | See `:help license`. 72 | 73 | [burnettk]: https://github.com/burnettk 74 | [iborovskyi]: https://github.com/iborovskyi 75 | [jasquat]: https://github.com/jasquat 76 | [mygithub]: https://github.com/burnettk 77 | [mysite]: http://notkeepingitreal.com 78 | [mytwitter]: http://twitter.com/kbbkkbbk 79 | [pathogen]: https://github.com/tpope/vim-pathogen 80 | [project]: https://github.com/burnettk/vim-jenkins 81 | [vundle]: https://github.com/gmarik/vundle 82 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # for vimrunner 2 | # require 'rspec/core/rake_task' 3 | # 4 | # RSpec::Core::RakeTask.new 5 | # 6 | # task :default => :spec 7 | 8 | task :ci => [:dump, :test] 9 | 10 | task :dump do 11 | sh 'vim --version' 12 | end 13 | 14 | task :test do 15 | sh 'bundle exec vim-flavor test ./test/jenkins.vim' 16 | end 17 | -------------------------------------------------------------------------------- /doc/jenkins.txt: -------------------------------------------------------------------------------- 1 | *jenkins.txt* Some vim integrations for jenkins. 2 | 3 | Author: Kevin Burnett 4 | License: Same terms as Vim itself (see |license|) 5 | 6 | This plugin is only available if 'compatible' is not set. 7 | 8 | *jenkins* 9 | See also the README at https://github.com/burnettk/vim-jenkins. 10 | 11 | FEATURES *jenkins-features* 12 | 13 | Interact with your jenkins instance via its API from within vim. 14 | 15 | *jenkins-:JenkinsValidateJenkinsFile* 16 | :JenkinsValidateJenkinsFile Validate your Jenkinsfile for syntactic correctness 17 | using the wonderful built-in support in the Jenkins API. 18 | 19 | *jenkins-:JenkinsShowLastBuildResult* 20 | :JenkinsShowLastBuildResult After you've documented your build plan path in a 21 | comment in your Jenkinsfile (// BUILD_PLAN: 22 | /my/hot/path/without/buildNumber), this will grab the 23 | current status of your build from the jenkins API. 24 | 25 | :JenkinsShowLastBuildLog After you've documented your build plan path in a 26 | comment in your Jenkinsfile (// BUILD_PLAN: 27 | /my/hot/path/without/buildNumber), this will show log 28 | of the last build from jenkins. 29 | 30 | :JenkinsRebuild After you've documented your build plan path in a 31 | comment in your Jenkinsfile (// BUILD_PLAN: 32 | /my/hot/path/without/buildNumber), this will rebuild 33 | the specified build number. 34 | 35 | ABOUT *jenkins-about* 36 | 37 | Grab the latest version or report a bug on GitHub: 38 | 39 | https://github.com/burnettk/vim-jenkins 40 | 41 | vim:tw=78:et:ft=help:norl: 42 | -------------------------------------------------------------------------------- /plugin/jenkins.vim: -------------------------------------------------------------------------------- 1 | " jenkins.vim 2 | " Maintainer: Kevin Burnett 3 | " Last Change: 2021 4 | 5 | if exists("g:loaded_vim_jenkins") 6 | finish 7 | endif 8 | let g:loaded_vim_jenkins = 1 9 | 10 | if !exists('g:jenkins_url') 11 | let g:jenkins_url = 'http://jenkins' 12 | endif 13 | 14 | function! CurrentFilePathLooksLikeJenkinsfile(currentFilename) "{{{ 15 | return a:currentFilename =~ ".jenkinsfile$" || a:currentFilename =~ "Jenkinsfile$" 16 | endfunction "}}} 17 | 18 | function! JenkinsFoundJenkinsfilePath() "{{{ 19 | let l:jenkinsfileFilename = "Jenkinsfile" 20 | if filereadable(l:jenkinsfileFilename) 21 | return l:jenkinsfileFilename 22 | else 23 | let l:currentFilename = expand('%:p') 24 | if CurrentFilePathLooksLikeJenkinsfile(l:currentFilename) && filereadable(l:currentFilename) 25 | return l:currentFilename 26 | else 27 | " we will later check empty() to see if we found a path 28 | return '' 29 | endif 30 | endif 31 | endfunction "}}} 32 | 33 | function! JenkinsHasBuildPlanPathInJenkinsfile(fullJenkinsfilePath) "{{{ 34 | return match(readfile(a:fullJenkinsfilePath), "BUILD_PLAN_PATH") != -1 35 | endfunction "}}}" 36 | 37 | function! JenkinsBuildPlanPathFromJenkinsfile(fullJenkinsfilePath) "{{{ 38 | let l:findBuildPlanCommand = 'grep BUILD_PLAN_PATH ' . a:fullJenkinsfilePath . ' | sed -e "s/.*BUILD_PLAN_PATH: //g"' 39 | return JenkinsChomp(system(l:findBuildPlanCommand)) 40 | endfunction "}}}" 41 | 42 | " LAST BUILD RESULT 43 | function! JenkinsShowLastBuildResult() "{{{ 44 | let l:basic_auth_options = '' 45 | if exists('g:jenkins_username') 46 | let l:basic_auth_options = '-u ' . g:jenkins_username . ':' . g:jenkins_password 47 | endif 48 | 49 | let l:fullJenkinsfilePath = JenkinsFoundJenkinsfilePath() 50 | if !empty(l:fullJenkinsfilePath) 51 | " check if Jenkinsfile includes BUILD_PLAN_PATH. otherwise error. 52 | if JenkinsHasBuildPlanPathInJenkinsfile(l:fullJenkinsfilePath) 53 | let l:jenkins_build_plan_path_from_jenkinsfile = JenkinsBuildPlanPathFromJenkinsfile(l:fullJenkinsfilePath) 54 | 55 | let l:jenkins_build_plan_api_path = l:jenkins_build_plan_path_from_jenkinsfile . '/lastCompletedBuild/api/json' 56 | let l:jenkins_build_plan_url = g:jenkins_url . l:jenkins_build_plan_api_path 57 | call JenkinsLogStuff('Fetching: ' . l:jenkins_build_plan_url) 58 | 59 | let l:build_info_response = JenkinsChomp(JenkinsShellOutToCurl('curl -k -s ' . l:jenkins_build_plan_url . ' ' . l:basic_auth_options)) 60 | let l:build_info = JenkinsJsonParse(JenkinsChomp(l:build_info_response)) 61 | call JenkinsLogStuff(l:build_info['fullDisplayName']) 62 | call JenkinsLogStuff(l:build_info['result']) 63 | else 64 | call JenkinsLogStuff('Jenkinsfile must include a BUILD_PLAN_PATH to use the show last build function') 65 | endif 66 | else 67 | call JenkinsNoJenkinsfileError() 68 | endif 69 | endfunction "}}} 70 | 71 | command! JenkinsShowLastBuildResult call JenkinsShowLastBuildResult() 72 | 73 | let g:jenkins_enable_mappings = get(g:, 'jenkins_enable_mappings', 1) 74 | 75 | if g:jenkins_enable_mappings == 1 76 | nnoremap jb :JenkinsShowLastBuildResult 77 | endif 78 | 79 | 80 | " REBUILD BUILDNUM 81 | function! JenkinsRebuild(buildNumber) "{{{ 82 | let l:basic_auth_options = '' 83 | if exists('g:jenkins_username') 84 | let l:basic_auth_options = '-u ' . g:jenkins_username . ':' . g:jenkins_password 85 | endif 86 | 87 | let l:fullJenkinsfilePath = JenkinsFoundJenkinsfilePath() 88 | if !empty(l:fullJenkinsfilePath) 89 | " check if Jenkinsfile includes BUILD_PLAN_PATH. otherwise error. 90 | if JenkinsHasBuildPlanPathInJenkinsfile(l:fullJenkinsfilePath) 91 | " check if build number is a number 92 | if a:buildNumber !~# '^\d\+$' 93 | call JenkinsLogStuff('Requires build number') 94 | else 95 | let l:basic_auth_options = '' 96 | if exists('g:jenkins_username') 97 | let l:basic_auth_options = '-u ' . g:jenkins_username . ':' . g:jenkins_password 98 | endif 99 | let l:jenkins_build_plan_path_from_jenkinsfile = JenkinsBuildPlanPathFromJenkinsfile(l:fullJenkinsfilePath) 100 | let l:jenkins_job_name = JenkinsChomp(substitute(system(l:findBuildPlanCommand),'^.*job/','','')) 101 | 102 | " Thanks nirzari 103 | " https://github.com/nirzari/groovy-scripts 104 | let l:rebuild_groovy = 'import hudson.model.*\n 105 | \import jenkins.model.Jenkins\n 106 | \ 107 | \ 108 | \def jobName = \"' . l:jenkins_job_name . '\"\n 109 | \ 110 | \def job = Jenkins.instance.getItemByFullName(jobName)\n 111 | \def build = ' . a:buildNumber . '\n 112 | \ 113 | \def my_job = job.getBuildByNumber(build)\n 114 | \def actions = my_job.getActions(ParametersAction)\n 115 | \println(my_job)\n 116 | \job.scheduleBuild2(0, actions.toArray(new ParametersAction[actions.size()])) 117 | \println(\"\")' 118 | 119 | let l:jenkins_script_url = g:jenkins_url . '/scriptText' 120 | call JenkinsLogStuff('Triggering rebuild') 121 | execute '!echo -e "' . l:rebuild_groovy . '" > /tmp/rebuild.groovy ; curl -k ' . l:basic_auth_options . ' --data-urlencode "script=$(< /tmp/rebuild.groovy)" ' . l:jenkins_script_url 122 | endif 123 | else 124 | call JenkinsLogStuff('Jenkinsfile must include a BUILD_PLAN_PATH to use the show last build function') 125 | endif 126 | else 127 | call JenkinsNoJenkinsfileError() 128 | endif 129 | endfunction "}}} 130 | 131 | command! -nargs=1 JenkinsRebuild call JenkinsRebuild() 132 | 133 | 134 | " LAST BUILD LOG 135 | function! JenkinsShowLastBuildLog() "{{{ 136 | let l:basic_auth_options = '' 137 | if exists('g:jenkins_username') 138 | let l:basic_auth_options = '-u ' . g:jenkins_username . ':' . g:jenkins_password 139 | endif 140 | 141 | let l:fullJenkinsfilePath = JenkinsFoundJenkinsfilePath() 142 | if !empty(l:fullJenkinsfilePath) 143 | if JenkinsHasBuildPlanPathInJenkinsfile(l:fullJenkinsfilePath) 144 | let l:jenkins_build_plan_path_from_jenkinsfile = JenkinsBuildPlanPathFromJenkinsfile(l:fullJenkinsfilePath) 145 | 146 | let l:jenkins_build_plan_api_path = l:jenkins_build_plan_path_from_jenkinsfile . '/lastBuild/consoleText' 147 | let l:jenkins_build_plan_url = g:jenkins_url . l:jenkins_build_plan_api_path 148 | call JenkinsLogStuff('Fetching: ' . l:jenkins_build_plan_url) 149 | 150 | let l:last_build_log = JenkinsChomp(JenkinsShellOutToCurl('curl -k -s ' . l:jenkins_build_plan_url . ' ' . l:basic_auth_options)) 151 | echo l:last_build_log 152 | else 153 | call JenkinsLogStuff('Jenkinsfile must include a BUILD_PLAN_PATH to use the show last build function') 154 | endif 155 | else 156 | call JenkinsNoJenkinsfileError() 157 | endif 158 | endfunction "}}} 159 | 160 | command! JenkinsShowLastBuildLog call JenkinsShowLastBuildLog() 161 | 162 | if g:jenkins_enable_mappings == 1 163 | nnoremap jl :JenkinsShowLastBuildLog 164 | endif 165 | 166 | 167 | function JenkinsLogStuff(logMessage) "{{{ 168 | echom a:logMessage 169 | if exists('g:jenkins_log_messages_to_disk_for_tests') 170 | if g:jenkins_log_messages_to_disk_for_tests == 'true' || g:jenkins_log_messages_to_disk_for_tests == true 171 | call JenkinsMylog(a:logMessage, 'jenkins.log') 172 | endif 173 | endif 174 | endfunction "}}} 175 | 176 | " http://stackoverflow.com/questions/23089736/how-do-i-append-text-to-a-file-with-vim-script 177 | function! JenkinsMylog(message, file) 178 | let l:operation = 'w >>' 179 | if !filereadable(a:file) 180 | let l:operation = 'w' 181 | endif 182 | new 183 | setlocal buftype=nofile bufhidden=hide noswapfile nobuflisted 184 | put=a:message 185 | execute l:operation a:file 186 | q 187 | endfun 188 | 189 | function JenkinsShellOutToCurl(curlCommand) "{{{ 190 | return system(a:curlCommand) 191 | endfunction "}}} 192 | 193 | function JenkinsCopyJenkinsfileIntoPlace(fullJenkinsfilePath) "{{{ 194 | execute 'silent !cp ' . a:fullJenkinsfilePath . ' /tmp/Jenkinsfile && perl -pi -e "s/^\@Library\(.*$//g" /tmp/Jenkinsfile && perl -pi -e "s/^import .*$//g" /tmp/Jenkinsfile' 195 | endfunction "}}} 196 | 197 | function! JenkinsValidateJenkinsFile() "{{{ 198 | let l:fullJenkinsfilePath = JenkinsFoundJenkinsfilePath() 199 | if !empty(l:fullJenkinsfilePath) 200 | let l:basic_auth_options = '' 201 | 202 | if !exists('g:jenkins_validation_username') 203 | let g:jenkins_validation_username = g:jenkins_username 204 | endif 205 | if !exists('g:jenkins_validation_password') 206 | let g:jenkins_validation_password = g:jenkins_password 207 | endif 208 | 209 | if exists('g:jenkins_validation_username') 210 | let l:basic_auth_options = '-u ' . g:jenkins_validation_username . ':' . g:jenkins_validation_password 211 | endif 212 | 213 | if !exists('g:jenkins_validation_url') 214 | let g:jenkins_validation_url = g:jenkins_url 215 | endif 216 | 217 | " This is the only way that works. Let's just write a function that 218 | " verifies it gets the gigantic string to execute and then mock the 219 | " function to get the input for testing. 220 | execute "!sh -c 'cp " . l:fullJenkinsfilePath . ' /tmp/Jenkinsfile && perl -pi -e "s/^\@Library\(.*$//g" /tmp/Jenkinsfile && perl -pi -e "s/^import .*$//g" /tmp/Jenkinsfile && curl -k -X POST -F "jenkinsfile=rj :JenkinsValidateJenkinsFile 246 | endif 247 | 248 | " Helper functions 249 | 250 | " credit to http://vi.stackexchange.com/questions/2867/how-do-you-chomp-a-string-in-vim 251 | function! JenkinsChomp(string) 252 | return substitute(a:string, '\n\+$', '', '') 253 | endfunction 254 | 255 | " credit to tpope 256 | function! JenkinsJsonParse(string) abort 257 | let string = type(a:string) == type([]) ? join(a:string, ' ') : a:string 258 | if exists('*json_decode') 259 | return json_decode(string) 260 | endif 261 | let [null, false, true] = ['', 0, 1] 262 | let stripped = substitute(string,'\C"\(\\.\|[^"\\]\)*"','','g') 263 | if stripped !~# "[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \n\r\t]" 264 | try 265 | return eval(substitute(string,"[\r\n]"," ",'g')) 266 | catch 267 | endtry 268 | endif 269 | throw "invalid JSON: ".string 270 | endfunction 271 | 272 | function! JenkinsNoJenkinsfileError() "{{{ 273 | call JenkinsLogStuff('This functionality requires a Jenkinsfile') 274 | endfunction "}}} 275 | -------------------------------------------------------------------------------- /test/jenkins.vim: -------------------------------------------------------------------------------- 1 | runtime plugin/jenkins.vim 2 | 3 | function! GetAllLogMessages() 4 | " https://stackoverflow.com/a/5442225/6090676 5 | redir => l:messages 6 | messages 7 | redir END 8 | return l:messages 9 | endfunction 10 | 11 | function! AssertLastLogMessage(message) 12 | let l:lastLogMessage = split(GetAllLogMessages(), "\n")[-1] 13 | Expect l:lastLogMessage ==# a:message 14 | endfunction 15 | 16 | function! JenkinsFoundJenkinsfilePath() "{{{ 17 | let l:jenkinsfileFilename = "Jenkinsfile" 18 | if filereadable(l:jenkinsfileFilename) 19 | return l:jenkinsfileFilename 20 | else 21 | if CurrentFilePathLooksLikeJenkinsfile(l:currentFilename) && filereadable(l:currentFilename) 22 | return l:currentFilename 23 | else 24 | " we will later check empty() to see if we found a path 25 | return '' 26 | endif 27 | endif 28 | endfunction "}}} 29 | 30 | unlet g:loaded_vim_jenkins 31 | source plugin/jenkins.vim 32 | 33 | describe 'loading_plugin' 34 | before 35 | call delete('tmp/test', 'rf') 36 | call mkdir('tmp/test', 'p') 37 | cd tmp/test 38 | end 39 | 40 | after 41 | cd - 42 | end 43 | 44 | context 'when loaded' 45 | it 'returns 1' 46 | Expect g:loaded_vim_jenkins ==# 1 47 | end 48 | end 49 | end 50 | 51 | describe 'setting_jenkins_url' 52 | context 'default' 53 | it 'is set' 54 | Expect g:jenkins_url ==# 'http://jenkins' 55 | end 56 | end 57 | context 'overridden' 58 | before 59 | let g:jenkins_url = 'http://my-hot-jenkins' 60 | end 61 | it 'is set' 62 | Expect g:jenkins_url ==# 'http://my-hot-jenkins' 63 | end 64 | end 65 | end 66 | 67 | describe 'JenkinsFoundJenkinsfilePath()' 68 | context 'with Jenkinsfile' 69 | before 70 | !touch Jenkinsfile 71 | end 72 | it 'finds it' 73 | Expect JenkinsFoundJenkinsfilePath() ==# 'Jenkinsfile' 74 | end 75 | end 76 | end 77 | 78 | describe 'JenkinsFoundJenkinsfilePath() in tmp/test' 79 | before 80 | call delete('tmp/test', 'rf') 81 | call mkdir('tmp/test', 'p') 82 | cd tmp/test 83 | !rm Jenkinsfile 84 | end 85 | 86 | after 87 | cd - 88 | end 89 | 90 | context 'with Jenkinsfile in tmp/test' 91 | before 92 | new 93 | w Jenkinsfile 94 | end 95 | after 96 | close! 97 | end 98 | it 'finds it' 99 | Expect JenkinsFoundJenkinsfilePath() ==# 'Jenkinsfile' 100 | end 101 | end 102 | 103 | context 'with hot.jenkinsfile' 104 | before 105 | new 106 | w hot.jenkinsfile 107 | end 108 | after 109 | close! 110 | end 111 | it 'finds it' 112 | Expect JenkinsFoundJenkinsfilePath() =~# 'hot.jenkinsfile$' 113 | end 114 | end 115 | end 116 | 117 | describe 'JenkinsHasBuildPlanPathInJenkinsfile()' 118 | before 119 | call delete('tmp/test', 'rf') 120 | call mkdir('tmp/test', 'p') 121 | cd tmp/test 122 | end 123 | 124 | after 125 | cd - 126 | end 127 | 128 | context 'with path' 129 | before 130 | new 131 | put! = '// BUILD_PLAN_PATH: /job/hot-dir/job/hot-app/main' 132 | w Jenkinsfile 133 | end 134 | after 135 | close! 136 | end 137 | it 'finds it' 138 | Expect JenkinsHasBuildPlanPathInJenkinsfile('Jenkinsfile') to_be_true 139 | end 140 | end 141 | 142 | context 'with no path' 143 | before 144 | new 145 | w Jenkinsfile 146 | end 147 | after 148 | close! 149 | end 150 | it 'finds nothing since nothing is there' 151 | Expect JenkinsHasBuildPlanPathInJenkinsfile('Jenkinsfile') to_be_false 152 | end 153 | end 154 | end 155 | 156 | describe 'JenkinsBuildPlanPathFromJenkinsfile()' 157 | before 158 | call delete('tmp/test', 'rf') 159 | call mkdir('tmp/test', 'p') 160 | cd tmp/test 161 | end 162 | 163 | after 164 | cd - 165 | end 166 | 167 | context 'with path' 168 | before 169 | new 170 | put! = '// BUILD_PLAN_PATH: /job/hot-dir/job/hot-app/main' 171 | w Jenkinsfile 172 | end 173 | after 174 | close! 175 | end 176 | it 'finds it' 177 | Expect JenkinsBuildPlanPathFromJenkinsfile('Jenkinsfile') ==# '/job/hot-dir/job/hot-app/main' 178 | end 179 | end 180 | 181 | context 'with no path' 182 | before 183 | new 184 | w Jenkinsfile 185 | end 186 | after 187 | close! 188 | end 189 | it 'finds nothing since nothing is there' 190 | Expect JenkinsBuildPlanPathFromJenkinsfile('Jenkinsfile') ==# '' 191 | end 192 | end 193 | end 194 | 195 | describe 'JenkinsJsonParse()' 196 | before 197 | call delete('tmp/test', 'rf') 198 | call mkdir('tmp/test', 'p') 199 | cd tmp/test 200 | end 201 | 202 | after 203 | cd - 204 | end 205 | 206 | context 'with hot json' 207 | before 208 | !touch Jenkinsfile 209 | end 210 | it 'parses it' 211 | Expect JenkinsJsonParse('{"hot": "json"}') ==# {"hot": "json"} 212 | Expect JenkinsJsonParse('{"hot": "json"}')["hot"] ==# "json" 213 | end 214 | end 215 | end 216 | 217 | describe 'JenkinsChomp()' 218 | it 'removes trailing newlines' 219 | Expect JenkinsChomp("hey\n\n\n") ==# 'hey' 220 | end 221 | end 222 | 223 | describe 'JenkinsValidateJenkinsFile()' 224 | before 225 | call delete('tmp/test', 'rf') 226 | call mkdir('tmp/test', 'p') 227 | cd tmp/test 228 | end 229 | 230 | after 231 | cd - 232 | end 233 | 234 | context 'when no Jenkinsfile' 235 | it 'prints an error' 236 | call JenkinsValidateJenkinsFile() 237 | call AssertLastLogMessage("This functionality requires a Jenkinsfile") 238 | end 239 | end 240 | " context 'when no Jenkinsfile' 241 | " before 242 | " new 243 | " put! = '// BUILD_PLAN_PATH: /job/hot-dir/job/hot-app/main' 244 | " w Jenkinsfile 245 | " end 246 | " after 247 | " close! 248 | " end 249 | " it 'finds it' 250 | " Expect JenkinsBuildPlanPathFromJenkinsfile('Jenkinsfile') ==# '/job/hot-dir/job/hot-app/main' 251 | " end 252 | " end 253 | " 254 | " context 'with no path' 255 | " before 256 | " new 257 | " w Jenkinsfile 258 | " end 259 | " after 260 | " close! 261 | " end 262 | " it 'finds nothing since nothing is there' 263 | " Expect JenkinsBuildPlanPathFromJenkinsfile('Jenkinsfile') ==# '' 264 | " end 265 | " end 266 | end 267 | --------------------------------------------------------------------------------