LoginSignup
0
1

More than 3 years have passed since last update.

Jenkins Pipeline (Multiple pipeline じゃない方) の注意点

Last updated at Posted at 2021-04-12

Jenkins 2.235.1 かつ Windows の話。
普段 Multiple pipeline を使用しているのだが、Multiple じゃない方を使ったときに意外と差異が多くて詰まった。
詰まったポイントを書いていく。

Lightweight checkout

repository clone 時の設定として "Lightweight checkout" という項目がある。デフォルトではチェックが付いているが、このとき Jenkins は Jenkinsfile のみを clone する。よって Jenkinsfile から他の bat 等を叩こうとしても bat は無い。そう言うことがしたい場合はチェックをオフにするか、自前で repository を clone してくる必要がある。
jenkins.jpeg

Declarative と Scripted の clone 先

最初に pipeline{} が来るのが Declarative syntax で、最初に node{} が来るのが Scripted syntax。
仮に Job 名を Jobname とした場合、Declarative syntax では Jenkins workspace に Jobname フォルダが生成されるが、Scripted syntax では JobName@script というフォルダが生成される。さらにこの Jobname@script フォルダは clone がうまく行われないケースがある(clone 先は Jobname@script フォルダなのにカレントディレクトリは Jobname フォルダになっていると思われる。あまり検証していない。)
よって Lightweight checkout を Off にする場合は Declarative syntax の方が無難。なお Declarative syntax でも script {} を使用した場合は両方のフォルダが生成されるが、この場合は Jobname@script の方は使用されないっぽい。

使用できる環境変数

Multiple pipeline では ${env.BRANCH_NAME} といった変数が使用できるが、Pipeline では殆どが使用できない。何が使用できないかは ${YOUR_JENKINS_URL}/pipeline-syntax/globals#env から確認可能。
jenkins2.jpeg

参照:https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables

0
1
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
1