如何从devops部署阶段检索cloud Foundry oauth令牌以设置自动扩展? [英] How to retrieve the cloud foundry oauth token from a devops deploy stage for setting up auto scaling?
问题描述
我正在尝试从devops管道部署阶段获取Cloud Foundry oauth-token:
I'm trying to get the cloud foundry oauth-token from a devops pipeline deploy stage:
...
cf push $CF_APP
...
accessToken=$(cf oauth-token | grep bearer | sed -e s/bearer/Bearer/g)
echo accessToken=$accessToken
...
# use token in Auto Scaling API call ...
curl $createPolicyUrl -X 'PUT' -H 'Content-Type:application/json' \
-H 'Accept:application/json' \
-H "Authorization:$accessToken" \
--data-binary @${policyJson} \
-s -o response.txt -w '%{http_code}\n'
echo命令的输出为:
The output from the echo command is:
accessToken=
如何检索oauth令牌?
How can I retrieve the oauth token?
请注意,尽管在部署脚本中没有执行cf login
,但在脚本ecen中cf push
仍然可以正常工作.因此,我假设cf oauth-token也不需要登录.这是一个有效的假设吗?
Note that cf push
works ok in the script ecen though there isn't a cf login
performed in the deploy script. Therefore, I'm assuming cf oauth-token would not need login either. Is this a valid assumption?
更新:我在部署脚本中添加了cf login
:
Update: I added cf login
to my deploy script:
...
cf push $CF_APP
...
cf login
accessToken=$(cf oauth-token | grep bearer | sed -e s/bearer/Bearer/g)
echo accessToken=$accessToken
...
输出:
cf login not allowed.
另请参阅我的类似问题在devops部署阶段重新配置可用性监视.
See also my similar question on reconfiguring availability monitoring in a devops deploy stage.
推荐答案
在运行cf oauth-token
命令之前,请确保先执行cf login
进行登录.另外,请确保双引号"Authorization:$accessToken"
,以便替换该变量.
Make sure to do a cf login
to log in before you run the cf oauth-token
command. Also make sure to double quote "Authorization:$accessToken"
so the variable is substituted.
更新:看起来您可以通过$CF_TOKEN
环境变量从脚本内访问oauth-token.该令牌与管道的所有者关联,而不是与运行当前管道阶段的用户关联.
Update: It looks like you can access the oauth-token from within the script via the $CF_TOKEN
environment variable. The token is associated with the owner of the pipeline, not the user running the current pipeline stage.
这篇关于如何从devops部署阶段检索cloud Foundry oauth令牌以设置自动扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!