0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[06] declarative pipeline の使用例 -- 例外を握り潰す(分散ビルド)

Last updated at Posted at 2021-10-10

概要

goto 文のようなことをするために例外を投げて且つ握り潰す.
waitUntil (== true の間ループする) で使うことがあったので、書き残しておく.

なお、使用した Jenkins バージョンは Jenkins 2.314 である.


        stage('A') {
            echo " in stage."
            parallel ( // 本記事では並列処理は気にしなくて良い
                "task1": {
                     // 何か処理をしているものとする.本記事では重要ではないので省略する
                },
                "task2": {
                    waitUntil { // true の間は継続する
                        try {
                            RC = sh (
                                     [
                                         script: "python3 /var/lib/jenkins/bin/is_finished.py", 
                                         returnStatus:true
                                     ]
                                 )
                            if (RC != 0) {
                                // 意図的に例外を生じさせて catch に進める
                                error message: "Continue"
                            }
                            echo "Finished"
                            false // false を定義することで waitUntil を脱出できる
                        } catch(error) {
                            true // 処理継続
                        }
                    }
                }
            )
        }
    }    

参考記事

https://qiita.com/i47_rozary/items/b05b52b3c16041f91196

 

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?