脚本任务可以覆盖Bamboo变量吗? [英] Can Bamboo variables be overridden by a Script task?

查看:125
本文介绍了脚本任务可以覆盖Bamboo变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣使用脚本任务覆盖这些Bamboo 计划变量用于后续任务,但我不确定是否可行或如何进行.看起来Bamboo允许对构建计划一直到特定分支的各个级别的变量覆盖,但是它们似乎都需要在Bamboo UI中定义值.这样做的问题是,它需要管理员特权才能修改这些变量,而其中一些变量需要由不具有此访问级别的开发人员来修改.作为解决方案,我希望能够在源存储库本身中存在的文件中指定一些变量替代.

尝试1:覆盖环境变量

我试图使用Powershell脚本并指定类似$env:bamboo_xyz = 'ABC'的方式来设置Bamboo公开的环境变量,但是似乎在指定任务上下文之后没有影响.是要分别为每个任务重新设置环境变量,还是在它们自己的上下文中执行它们,但是我对文档是否一清二楚.

更新:从一些测试中可以看出,在同一作业中,在一个脚本任务中设置的环境变量在后续脚本任务中不可用.除了Bamboo中的硬编码值之外,这使我没有明显的方法来覆盖变量.

尝试2:使用 Bamboo注入变量插件任务

我尝试使用解决方案

环境变量仅在当前会话中有效.因此,如果Bamboo启动一个脚本(一个powershell会话)完成该脚本,然后启动一个新的powershell脚本(New Session),则不会保留环境变量.

因此,有几个选项可以在每个脚本中设置变量. 或在过程开始时使用注册表进行设置.并根据需要在上一步/脚本中将其设置回默认值.

I'm interested in using a script task to override one of these Bamboo plan variables for subsequent tasks but I'm not sure if it's possible or how to go about doing so. It appears that Bamboo allows for various levels of variable overrides for Build Plans all the way down to particular branches however they all seem to require defining the values within the Bamboo UI. The problem with this is that it requires admin privileges to modify these variables whereas some of them need to be modified by developers that do not have this level of access. As a solution I want to be able to specify some variable overrides in files that exist in the source repository itself.

Attempt 1: Overriding environment variables

I've attempted to set the environment variables exposed by Bamboo using a Powershell script and specifying something like $env:bamboo_xyz = 'ABC' but it doesn't seem to have an effect past the task context in which it was specified in. Presumably Bamboo must be re-setting the environment variables individually for each task or executing them within their own contexts but it's not clear to me exactly from the documentation.

UPDATE: It appears from some testing that environment variables set in one Script task are not available in subsequent Script tasks in the same Job. This leaves me with no apparent way to override variables based on anything other than hard coded values in Bamboo.

Attempt 2: Using the Bamboo Inject Variables Plugin task

I've tried using the Bamboo Inject Variables Plugin task to override variables but because what appears to be a required namespace parameter it only seems to be able to define new variables and not override existing ones.

解决方案

Enviroment variables are only valid in the current session. So if bamboo starts one script ( one powershell session ) completes that and then start a new powershell script ( New Session ) the enviroment variable will not be kept.

So then there are a few options, set the variable in each script. Or set it using registry at the start of the process. And if ncessary set it back to default value in the last step/script.

这篇关于脚本任务可以覆盖Bamboo变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆