powershell - 在 jenkins 文件中编写 Powershell 或直接在 jenkins 中编写
问题描述
我是 Jenkins 的新手,我想用它来自动化一些任务。Powershell 插件已安装和配置,目前可以使用。我已经有脚本来处理我的任务,比如说 12 个脚本文件,那么 12 个脚本文件。我有一些关于如何最好地将其集成到 Jenkins 管道中的问题。
我想知道是否最好将我的 Powershell 脚本作为单独的文件保留,或者将它们放在存储库中并让 Jenkins 将它们拉下来并运行它们,或者将 Powershell 文件的内容直接复制到 Jenkins 中并从那里运行它们而不是调用单个文件。
其次,我的脚本需要在它们之间传递值。是否有可能有一个 Jenkins 管道,它为不同的任务调用多个 Powershell 脚本文件,我可以将任务 1 中的值传递给 2 等吗?
我想知道最好的方法,调用 Ps 脚本文件并将值返回到 Jenkins 变量的示例会很好,无论是调用 PS 文件还是直接运行 Powershell 代码。
解决方案
Where you store the PowerShell scripts depends a lot on the details and preference. Personally, I would put them right in the Jenkinsfile if I only needed them at this one place. If I needed them in different places, I'd put them in Git.
You can return the stdout of a PowerShell command, store it in a variable and use that in another PowerShell script like so:
def msg = powershell(returnStdout: true, script: 'Write-Output "PowerShell is mighty!"')
powershell "use $msg here"
Problem here is that you only can get strings out of it and no PowerShell objects. You can also return the exit code and store it in a variable.
For more information, see this.
推荐阅读
- python - PHP找不到张量流
- c# - 在 Blazor 中的 Page 和 NavMenu 之间交换数据
- azure - Azure Pipelines YAML:意外的值“变量”
- python - 使用根据数据排序的标签创建数据框
- scala - Scala - 字符串和列对象
- powerbi - SSAS表格/分析服务多币种输入多对多-多币种输出
- php - 如何在 PHP 中的 JSON 响应中编码日期,例如“/Date(1365004652303-0500)/”?
- python - 具有同步下拉菜单的多页 Dash 应用程序不起作用
- python - 从 requirements.txt 安装 PyTorch
- android-studio - 包名称更改后 Admob 广告未显示