Azure Devops 릴리스 파이프 라인 (yaml이 아닌 클래식 편집기 사용)이 있고 인라인 powershell 스크립트에서 변수를 설정하는 데 문제가 있습니다. 스크립트의 관련 부분은 다음과 같습니다.
Write-Host "Web is $web"
Write-Host "App is $app"
Write-Host "##vso[task.setvariable variable=MyWebEnv;]$web"
Write-Host "Set Web to $($MyWebEnv)"
Write-Host "##vso[task.setvariable variable=MyAppEnv;]$app"
Write-Host "Set App to $(MyAppEnv)"
로그 파일은 내 $ web 및 $ app 변수가 올바른 값을 보유하고 있지만 설정이 작동하지 않음을 나타냅니다.
$ ($ env : MyWebEnv) 및 $ (MyWebEnv) 형식으로 값을 작성하려고 시도했으며 두 형식 모두 ADO 변수가 올바르게 설정되지 않았 음을 나타냅니다.
내 변수는 파이프 라인의 변수 탭에서 정의됩니다. 대기열 시간에 설정 가능으로 설정됩니다. 정의에 값을 설정하지 않고 초기 값을 시도했는데 초기 값을 덮어 쓰지 않는 것을 알 수 있습니다.
자체 호스팅 에이전트와 Azure Pipelines Hosted 에이전트 모두에서 실행 해 보았습니다. 동일한 결과입니다. 문제없이 비슷한 작업을 수행하는 또 다른 릴리스 파이프 라인이 있습니다.
후속 단계에서 변수를 사용하려고합니다.
스테이지가 실행되는지 여부를 제어하기 위해 변수를 사용하고 싶기 때문에 변수를 파일이나 다른 것에 쓰고 싶지 않습니다.
편집 : Levi의 의견에 따라 isOutput = true를 추가하고 동일한 단계의 후속 단계에서 변수를 검사하려고 시도했습니다. 후속 단계에서도 표시되지 않습니다.
========================================================================= Edit 2: I must have had a non visible character somewhere. I was composing the powershell in an external editor (just so I had more space) and pasting into the inline textbox in ADO - when I typed in the exact same thing I had into the editor it started working - sort of.
I can set the variable now and it's appearing in the task below, but what I really want is to use it in the next stages - in the IIS deployment group to control that IIS server A runs, but IIS server B doesn't. I'm attempting to do this in the Additional Options Run Expression.
I've tried and(succeeded(), eq(variables['MyWebEnv'], 'myvalue')
or (where MyOutput. is the name given to my output reference when setting the variable) and(succeeded(), eq(variables['MyOutpub.MyWebEnv'], 'myvalue')
or and(succeeded(), eq(variables['MyOutpub_MyWebEnv'], 'myvalue')
To clarify, I'm doing this on the IIS Deployment Group itself, and not on any of the tasks within that group.
I keep seeing that the deployment is skipped due to: Evaluating: eq(variables['MyOutput,MyWebEnv'], 'myvalue') Expanded: eq(Null, 'myvalue') Result: False
As Levi Lu mentioned you can access pipeline variables in the next step. So if you set variables like this here:
$web ="some-web"
$app ="some-app"
Write-Host "##vso[task.setvariable variable=MyWebEnv;]$web"
Write-Host "##vso[task.setvariable variable=MyAppEnv;]$app"
then you can read them in this way:
Write-Host "Set Web to $(MyWebEnv)"
Write-Host "Set App to $(MyAppEnv)"
And if you want to access them via env variables you should use this syntax:
Write-Host "Set Web to $($env:MYWEBENV)"
Write-Host "Set App to $($env:MYAPPENV)"
Answer for EDIT 2:
What you actually need is output cross stage variables which is supported in YAML but not in classic pipelines. Please check this topics. You can overcome this but it requires an extra effort as it shown here. However, please remember that you can't publish an artifact from release pipeline.
여기 에 크로스 스테이지 변수에 대한 문서가 있지만 위와 같이 YAML에서 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다