无法在PHP和phing中访问jenkins的BUILD_NUMBER环境变量

Via entry point file

I invoke a php script from jenkins, using the "Execute shell" section -

php entry.php branch_name_${branch_name} deployment_group_${deployment_group} rollback_${rollback} last_successful_revision_${last_successful_revision} sanity_check_duration_start_time_delay_sec_${sanity_check_duration_start_time_delay_sec} sanity_check_duration_end_time_delay_sec_${sanity_check_duration_end_time_delay_sec}

I tried accessing the jenkins build number there, but it was not available -

$build_number = exec(${BUILD_NUMBER});
file_put_contents('/home/jenkins/deployment_beta/phing/new_test_sandeepan.txt', "
 Build number is ".$build_number, FILE_APPEND);

Log lin in that file shows -

 Build number is

Via phing xml file

I also tried accessing it in a phing xml file -

<appspecFileModifications buildName="${BUILD_NUMBER}" />

This xml file is invoked via the above mentioned entry file (php script), like this -

$last_output = exec("phing -q -Dbranch_name=".$branchName, $output);

I checked other questions like - How to use jenkins to declare BUILD_NUMBER environment variable in gradle? Jenkins - How to access BUILD_NUMBER environment variable

douji4223
douji4223 随意添加这个答案,我会接受它:)
3 年多之前 回复
doufei7516
doufei7516 好的,我使用getent()得到它。谢谢!
3 年多之前 回复
duangewu5234
duangewu5234 我尝试转储$_ENV变量,但它显示为空-file_put_contents('/home/jenkins/deployment_beta/phing/new_test_sandeepan.txt',“ 内部版本号为”。$_ENV['BUILD_NUMBER']。“和所有环境变量是“.print_r($_ENV,1)。” “,FILE_APPEND);.输出-内部编号是,所有环境变量都是数组()
3 年多之前 回复
doulue1949
doulue1949 不,执行官毫无意义。环境变量应该是$_ENV
3 年多之前 回复
dongmeirang4679
dongmeirang4679 我应该在exec中添加echo吗?无论如何,我也在入口点php文件中试过这个-$last_output=exec(“phing-q-Dbuild_number=${BUILD_NUMBER}”,$output);
3 年多之前 回复
douxian9010
douxian9010 为什么要执行内部版本号?
3 年多之前 回复

1个回答

With Phing you would be able to get environment variables with a prefixed env.

    <appspecFileModifications buildName="${env.BUILD_NUMBER}" />

All variables from $_SERVER are available in this way.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问