vsts build Agent Shell 提供密码

vsts build Agent Shell provide password

我目前正在为我们的 DevOps 创建构建代理。 使用代理,我想通过 unix 服务器上的 shell 脚本停止 solr。问题是,我需要输入密码才能停止服务。

有没有一种简单的方法可以在 shell 脚本中提供密码?当前脚本:

service solr stop

抛出以下错误:

2020-03-12T12:50:27.0480993Z Successfully connected.
2020-03-12T12:50:27.0483958Z service solr stop
2020-03-12T12:50:29.7903365Z 
2020-03-12T12:50:29.8193011Z ##[error]Failed to stop solr.service: Interactive authentication required.
2020-03-12T12:50:29.8208401Z 
2020-03-12T12:50:29.8208979Z 
2020-03-12T12:50:29.8209589Z ##[error]See system logs and 'systemctl status solr.service' for details.
2020-03-12T12:50:29.8209971Z 
2020-03-12T12:50:29.8210587Z ##[error]Command failed with errors on remote machine.
2020-03-12T12:50:29.8341862Z ##[section]Finishing: stop solr

我也尝试在脚本中提供密码,例如:

echo <password> | sudo -S service solr stop

它在本地服务器上工作,但构建服务器抛出:

2020-03-12T12:52:17.9543478Z Successfully connected.
2020-03-12T12:52:17.9545108Z echo *** | sudo -S service solr stop
2020-03-12T12:52:18.9946984Z ##[error][sudo] password for ***: 
2020-03-12T12:52:23.4808034Z ##[error]Command failed with errors on remote machine.
2020-03-12T12:52:23.5019910Z ##[section]Finishing: stop solr

关于如何使用 shell 脚本远程停止 solr 的任何其他想法?

如前所述,我找到了一个解决方案并 post 在另一个 post 中编辑了它。这是答案 link: