How to read Bamboo variables during code execution
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
本記事で説明している手順は、現時点でのものとなります。そのため、一部のお客様で特定の状況下で動作したという報告がありますが、正式にサポートされているわけではなく、お客様の特定のシナリオで動作することを保証するものではありません。
本番環境での実施の前に一通り非本番環境で検証し、成功しなかった場合にはサポートされている代替案にフォール バックしてください。
要約
It's not possible to read Bamboo global variables when executing code, as this would pose a security risk and expose internal information. This article covers workarounds to pass Bamboo variables to the builders.
環境
All Bamboo versions, with Maven, Ant, or other builders.
ソリューション
Passing variables as parameters
Although Bamboo variables are not directly available in the builder execution context (Maven, Ant, etc.), they can be passed as parameters to the builder. Please refer to Passing Bamboo variables to a build script for steps.
環境変数
If you're using Maven or Ant as the build tool, it's possible to add environment variables to those apps, externally, and read them in the Java code. See Accessing Maven properties in Java and Ant: Using Environment Variables.
Script task
You can add a Script task that does and echo
of the value of the Bamboo Global variable to a file, and then have your Java code read it from that file.
Since Bamboo Global Variables are available within Bamboo's tasks, the Script task would have access to the value and could be used to output it to the system, which could then be used by the Java code.
Shell variables
If your goal is to use the variable to name files build by the builder tools, you can also set a variable in a shell
script, and use it to rename the files manually.