![将加密值从 xml 文件传递给 ms build 命令](https://linux22.com/image/759542/%E5%B0%86%E5%8A%A0%E5%AF%86%E5%80%BC%E4%BB%8E%20xml%20%E6%96%87%E4%BB%B6%E4%BC%A0%E9%80%92%E2%80%8B%E2%80%8B%E7%BB%99%20ms%20build%20%E5%91%BD%E4%BB%A4.png)
我有一个包含密码的 xml 文件。我必须将这些密码从 xml 文件传递到 MSBUILD 命令中的密码属性。有人可以指导我吗
XML文件:
<?xml versio------>
<configuration>
<password>newpassword</password>
</configuration>
我的 msbuild 命令是:
Msbuild "projectpath" /p:deployonbuild=true /p:username='user's /p:password=' '
答案1
有一个xml
模块https://docs.ansible.com/ansible/latest/collections/community/general/xml_module.html这里有一个从 XML 文件中检索 xml 值的示例
# Consider the following XML file:
#
# <business type="bar">
# <name>Tasty Beverage Co.</name>
# <beers>
# <beer>Rochefort 10</beer>
# <beer>St. Bernardus Abbot 12</beer>
# <beer>Schlitz</beer>
# </beers>
# <rating subjective="true">10</rating>
# <website>
# <mobilefriendly/>
# <address>http://tastybeverageco.com</address>
# </website>
# </business>
# Retrieve and display the number of nodes
- name: Get count of 'beers' nodes
community.general.xml:
path: /foo/bar.xml
xpath: /business/beers/beer
count: yes
register: hits
- ansible.builtin.debug:
var: hits.count
# ...
# How to read an attribute value and access it in Ansible
- name: Read an element's attribute values
xml:
path: /foo/bar.xml
xpath: /business/website/validxhtml
content: attribute
register: xmlresp
- name: Show an attribute value
debug:
var: xmlresp.matches[0].validxhtml.validatedon
您可以根据自己的需要采用它。在 Ansible 2.9 中,请使用xml
代替community.general.xml
,并注意安装必要的库(lxml)