Cách đưa biến môi trường thành một phần của một commandline ở PowerShell

Tôi gặp một bài toán như thế này:
Command tôi cần chạy:

.\octo.exe deploy-release --project ""ClientPortal"" --channel $ClientPortal_Channel --version=$ClientPortal_ReleaseNumber --deployto $ClientPortal_Env --ignoreSslErrors $ClientPortal_Tenant --progress --updateVariables
Enter fullscreen mode
Exit fullscreen mode

Đặc biệt với $ClientPortal_Tenant là một chuỗi mà tôi muốn nó trở thành một phần của command trên.

Giá trị của $ClientPortal_Tenant là:
--tenant ABC --tenant ABD --tenant ABE --tenant ABX

Nhưng khi thực hiện, thì báo lỗi ngay, vì biến môi trường trong trường hợp này được hiểu như một argument, ko phải là một thành phần của command.

Để giải quyết, ta sử dụng lệnh Invoke-Expression, một command trong powershell cho phép thực thi lệnh từ một chuỗi có sẵn.

Sửa lại như sau:

$ClientPortal=".\octo.exe deploy-release --project ""ClientPortal"" --channel $ClientPortal_Channel --version=$ClientPortal_ReleaseNumber --deployto $ClientPortal_Env --ignoreSslErrors $ClientPortal_Tenant --progress --updateVariables"
> Invoke-Expression $ClientPortal
Enter fullscreen mode
Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Smart homes let us control everything from mowers to home security with our phones. Free 2025 jamb questions and answers cbt answers jamb / jamb 2025 answers cbt answers jamb. Urgent and important matrix 4 quadrants life skills.