在舞台上部署工作之前运行其他工作

发布于 2025-02-06 09:44:11 字数 539 浏览 5 评论 0 原文

在部署作业运行之前,是否可以在作业中运行任务/脚本?我在环境中获得了批准,我希望由部署作业触发,但是它似乎需要在运行JOB1之前获得批准,而不是在Job1中运行任务,然后在运行部署工作之前要求批准。

我希望它在“ Job1”中运行所有工作,然后要求对部署作业进行批准。这可能吗?

我有类似于以下内容:

- stage: 1
variables:
  - group: global
jobs:
  - job: 'job1'
    steps:
      - task: DownloadPipelineArtifact@2
        ...

      - task: ExtractFiles@1
        ...

      - script: |
        ...

  - deployment:
    environment: DEV
    strategy:
      runOnce:
        deploy:
          steps:
            - script: |
                ...

Is it possible to run tasks/scripts within a job before a deployment job runs? I have an approval on the environment, which I want triggered by the deployment job, but it seems to want the approval before it runs job1 instead of running the tasks within job1 and then asking for approval before running the deployment job.

I want it to run all of the jobs within 'job1' and then ask for approval on the deployment job. Is this possible?

I have something similar to the below:

- stage: 1
variables:
  - group: global
jobs:
  - job: 'job1'
    steps:
      - task: DownloadPipelineArtifact@2
        ...

      - task: ExtractFiles@1
        ...

      - script: |
        ...

  - deployment:
    environment: DEV
    strategy:
      runOnce:
        deploy:
          steps:
            - script: |
                ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烛影斜 2025-02-13 09:44:11

不幸的是,不。 扩展模板,然后在管道执行之前评估管道中的所有依赖关系。例如,运行时确定管道是否有权使用变量组 +服务连接,或者允许执行管道的人员使用这些资源。

它在每个阶段都做同样的事情。在执行之前,它评估工作中的依赖项,并确定需要批准或检查。它将这些“检查”泡出来。开始一个舞台并完成工作的一半是为了意识到舞台首先不应该执行舞台是相当危险的。

重要的是要注意,“部署”是一种“作业”,每种 job 可能会在不同的代理商上运行,因此下载工件以节省时间(这似乎是在您的示例)无法如​​您所示。

如果您想暂停管道中执行中期执行并等待用户 - interaction,则有`手动验证任务'可以暂停并等待用户单击“继续”。这没有强制执行谁可以单击,但它通知一组用户,该任务正在等待他们的参与。重要的是要召集此任务是 agentless :它不会在您的代理池中运行。一个很好的参考示例将在将流量重新降低到网站(流量管理器,部署插槽等)之前暂停。

Unfortunately, no. The pre-process step within the pipeline run expands the templates and then evaluates all the dependencies within the pipeline before the pipeline executes. For example, the runtime determines if the pipeline has permission to use variable groups + service connections, or that the person executing the pipeline is allowed to consume those resources.

It does the same thing for each stage. Prior to execution, it evaluates the dependencies within the jobs and determines if Approvals or Checks are required. It bubbles these "checks" to the Stage. It would be fairly dangerous to start a stage and get halfway through the work only to realize the stage should never been executed in the first place.

It is important to note that "deployment" is a type of "job", and each job potentially runs on different agents, so downloading the artifacts to save time (which is what appears to be happening in your example) won't work as you've illustrated.

If you want to pause the execution of the pipeline mid-execution and wait for user-interaction there is the `Manual Validation Task' which can pause and wait for a user to click continue. This doesn't enforce who's allowed to click, but it notify a set of users that the task is waiting for their involvement. It's important to call out that this task is agentless: it doesn't run in your agent pool. A good reference example would be pausing before re-enabling traffic to a website (Traffic Manager, Deployment Slot, etc).

酒几许 2025-02-13 09:44:11

在部署作业运行之前,是否可以在作业中运行任务/脚本?

是的

我对环境有批准,我希望由部署作业触发,但是它似乎需要在运行JOB1的批准之前,而不是在Job1中运行任务,然后在运行部署工作之前要求批准。 /p>

如果我正确理解的话,您(像我一样)想准备一个构建,并与管道互动,以将go-nogo与其他管道的部署到环境中。

如果是这种情况,我不建议上述情况

,那么我必须说您需要两个不同的管道。

  1. 将为环境创建构建,而无需将环境附加到构建上。 从1号出版此伪影
  2. ,然后在特定环境中进行部署。

环境批准必须在不同的管道中完成,您可以从第一个构建中获取工件。

我建议在上面的方案中推荐

以下一部分使用多个阶段。开发,舞台和prd。
开发环境不需要验证,而是其他两个需求。因此,就我的开发而言,在Job WaitforValidation 时,我正在检查上一个构建是否成功,并且阶段是否不是开发。如果是这样,则它绕过工作并直接进入Nest作业,部署。
如果 WaitforValidation 作业没有绕过,则需要验证以继续使用管道。
有很好

  1. 在工作部署中,如果>可能是您问题的范围,则有两个,但如果有人会看到以后的情况,则 请继续进行构建
  2. 如果阶段不是开发,并且如果作业 WaitforValidation 成功,
    然后继续构建。
parameters:
  - name: 'stages'
    type: object

    default:
      - stage: Development
        dependsOn:

      - stage: Staging
        dependsOn: 'Development'

      - stage: Production
        dependsOn: 'Staging'

stages:
  - ${{each stage in parameters.stages}}:
      - stage: ${{ stage.stage }}
        dependsOn: ${{ stage.dependsOn }}
        displayName: ${{ stage.stage }}
        pool:
          vmImage: $(vmImageName)

        jobs:
          - job: Build
            displayName: Build for ${{ stage.stage }}
            steps:
              - script: |

       ... <code/steps/jobs goes here>

              - publish: $(Build.ArtifactStagingDirectory)
                artifact: '${{ stage.stage }}.$(ArtifactName)'

          - ${{ if ne(stage.stage, 'Development') }}:
              - job: waitForValidation
                displayName: 'Validation to Deploy $(ArtifactName) to ${{ stage.stage }} - $(ArtifactName), ${{variables.ArtifactName}}, and $[ ArtifactName ]'
                condition: and(succeeded(), ne('${{ stage.stage }}', 'Development'))
                dependsOn: 'Build'
                pool: server
                timeoutInMinutes: 43200 # job times out in 30 days
                steps:
                  - task: ManualValidation@0
                    timeoutInMinutes: 1 # task times out in 1 day
                    inputs:
                      notifyUsers:
                      instructions: 'Please validate the build configuration and resume'
                      onTimeout: reject

          - deployment: ${{ stage.stage }}
            displayName: Deploy to ${{ stage.stage }}
            environment: ${{ stage.stage }}
            ${{ if eq('${{ stage.stage }}', 'Development') }}:
              dependsOn: 'Build'
              condition: and(eq(dependencies.Build.result,'Succeeded'), ne(variables['Build.Reason'], 'PullRequest'))
            ${{ if ne('${{ stage.stage }}', 'Development') }}:
              dependsOn: 'waitForValidation'
              condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
            strategy:
              runOnce:
                deploy:
                  steps:
                    - task: Bash@3
                      inputs:
                        targetType: 'inline'
                        script: |
                          <rest of deployment>


我希望我与您的问题相提并论。

Is it possible to run tasks/scripts within a job before a deployment job runs?

Yes

I have an approval on the environment, which I want triggered by the deployment job, but it seems to want the approval before it runs job1 instead of running the tasks within job1 and then asking for approval before running the deployment job.

If I understand correctly, you (like me) want to prepare a build and have a human interact with the pipeline to give the go-nogo to the rest of the pipeline which is the deployment to an environment.

What I do not recommend for the above scenario

If that's the case, then I have to say that you need two different pipelines.

  1. would create the build for the environment, without attaching the environment to the build. Publish this artifact
  2. Pick the artifact from No.1 and then have a deployment with the specific environment.

the environmental approval has to be done in a different pipeline where you pick up the artifact from the first build.

What I do recommend for the above scenario

The following part is using multiple stages. Dev, staging and prd.
Dev environment does not need a validation but other two needs. So, in my case of dev, while on job waitForValidation I am checking if the previous build was successful and if the stage is not development. If it is, then it bypasses the job and goes directly to the nest job, deployment.
In case the waitForValidation job is not bypassed, a validation is needed to continue further with the pipeline.
In job deployment, there are two ifs probably out of your scope of the question but good to have in case someone else sees that in the future:

  1. If stage is development and if build job is successful, then continue with build
  2. if stage is not development and if job waitForValidation was successful
    then continue with build.
parameters:
  - name: 'stages'
    type: object

    default:
      - stage: Development
        dependsOn:

      - stage: Staging
        dependsOn: 'Development'

      - stage: Production
        dependsOn: 'Staging'

stages:
  - ${{each stage in parameters.stages}}:
      - stage: ${{ stage.stage }}
        dependsOn: ${{ stage.dependsOn }}
        displayName: ${{ stage.stage }}
        pool:
          vmImage: $(vmImageName)

        jobs:
          - job: Build
            displayName: Build for ${{ stage.stage }}
            steps:
              - script: |

       ... <code/steps/jobs goes here>

              - publish: $(Build.ArtifactStagingDirectory)
                artifact: '${{ stage.stage }}.$(ArtifactName)'

          - ${{ if ne(stage.stage, 'Development') }}:
              - job: waitForValidation
                displayName: 'Validation to Deploy $(ArtifactName) to ${{ stage.stage }} - $(ArtifactName), ${{variables.ArtifactName}}, and $[ ArtifactName ]'
                condition: and(succeeded(), ne('${{ stage.stage }}', 'Development'))
                dependsOn: 'Build'
                pool: server
                timeoutInMinutes: 43200 # job times out in 30 days
                steps:
                  - task: ManualValidation@0
                    timeoutInMinutes: 1 # task times out in 1 day
                    inputs:
                      notifyUsers:
                      instructions: 'Please validate the build configuration and resume'
                      onTimeout: reject

          - deployment: ${{ stage.stage }}
            displayName: Deploy to ${{ stage.stage }}
            environment: ${{ stage.stage }}
            ${{ if eq('${{ stage.stage }}', 'Development') }}:
              dependsOn: 'Build'
              condition: and(eq(dependencies.Build.result,'Succeeded'), ne(variables['Build.Reason'], 'PullRequest'))
            ${{ if ne('${{ stage.stage }}', 'Development') }}:
              dependsOn: 'waitForValidation'
              condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
            strategy:
              runOnce:
                deploy:
                  steps:
                    - task: Bash@3
                      inputs:
                        targetType: 'inline'
                        script: |
                          <rest of deployment>


I hope I am in par with your questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文