9
7

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 5 years have passed since last update.

jenkinsのスクリプト間で変数を共有したい

Last updated at Posted at 2017-10-26

jenkinsのシェルスクリプトを書いていると、スクリプトAの結果をスクリプトBで参照したい場合などがあると思います。その時の手法を紹介します。

EnvInject Plugin

こちらのプラグインを使います。
https://wiki.jenkins.io/display/JENKINS/EnvInject+Plugin

使い方

シェルスクリプトAの実行

PARAMという環境変数をvariables.txtというファイルに出力保存しておきます

shellA
TMP="test"
echo -e "PARAM=$TMP" >> variables.txt

環境変数のインジェクト

先ほど保存したvariables.txtを読み込み、そこに定義された変数を環境変数として読み込みます。
スクリーンショット 2017-10-26 14.00.46.png

変数を参照する

あとは他の環境変数のようにアクセスできます

shellA
echo $PARAM
# -> testと出力される
9
7
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
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?