3

I am trying to convert classic Azure pipelines to YAML.

however, I couldn't find any documents on how can I have an environment deployment utilize a previous build artifact? i.e. if we build and deploy to dev, after testing how can we build that exact same artifact of the build to another environment (such as integration or staging slot)? I don't want to do a whole build again as then we will have a different code base if changes were made in master in the meantime.

I that something possible with YAML pipeline, if so should I approach to implement this?

Auto geek
  • 464
  • 1
  • 6
  • 21
  • This is a great question that I'm struggling to answer also. It seems that you can have a seperate deploy pipeline that can refer a prior build artifact. It seems to me that you need to add a parameter to the deploy and literally plug in the build number to grab that artifact. – Nick.Mc Jan 28 '22 at 00:35

2 Answers2

1

Your YAML pipeline can specify what resources it needs. You can specify an existing build or another pipeline.

resources:
  pipelines:
  - pipeline: SmartHotel-resource # identifier for the resource (used in pipeline resource variables)
    source: SmartHotel-CI # name of the pipeline that produces an artifact

see:

As an alternative, you can create a multi-stage pipeline. Where your pipeline specifies both the build as well as the deployment steps:

stages:
- stage: A
  jobs:
  - job: A1
  - job: A2

- stage: B
  jobs:
  - job: B1
  - job: B2 

See:

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • 2
    with the multi-stage pipeline, we also have to run the build all the time when deploying that build to any of the environments right? since in classic pipeline they have a concept of release where you can take whatever build artifact you want and deploy it to whatever environments. which means you don't have to run the build every time you deploy to the environment. so my question is, is that something possible with YAML pipelines where you don't have to run builds(as you can choose the previous build) in order to deploy it to whatever environment. @jessehouwing – Auto geek Feb 01 '21 at 16:11
  • 3
    Yes, so create a pipeline and set the resources to point to another build or pipeline (instead of a repo). If needed add a parameter to set the exact build number. – jessehouwing Feb 01 '21 at 21:03
1

Is that something possible with YAML pipeline, if so should I approach to implement this?

Download artifact task will be auto injected only in the deploy hook for deployment jobs. To stop downloading artifacts, use - download: none or choose specific artifacts to download by specifying Download Pipeline Artifact task.

You can refer to the document about descriptions of lifecycle hooks and Artifacts in release and deployment jobs.

Walter
  • 2,640
  • 1
  • 5
  • 11
  • but since it is a multi-stage YAML pipeline where I have one stage for build and another stage for deployment, then I have to run the build stage first which producing a newer artifact. so how to consume old artifacts in YAML (for deployment stage) without running build within the same pipeline. since Azure Classic Pipeline has 2 concepts of build and release where you can take whatever build artifact version to deploy to whatever environment you choose without running the build pipeline. with YAML is that possible? @Walter Qian-MSFT – Auto geek Feb 01 '21 at 16:38
  • @Autogeek You can download specific version of your artifacts in your Download Pipeline Artifact task. If you already have available artifacts, you can skip the build stage. – Walter Feb 02 '21 at 03:19
  • I don't find a way to skip the build stage by having the build and release stages in 1 pipeline. as it says "Ensure that skipped stages do not produce any artifacts required by later stages" when I skip the build stage. However, I can achieve this by utilizing 2 pipelines. 1 for the build which produces the build artifacts and 1 pipeline for the release stage where I can use the resources section and pick the older build version and deploy it to release stages. Am I missing anything with the multi-stage build-release YAML pipeline? thanks @Walter Qian-MSFT – Auto geek Feb 16 '21 at 14:29
  • @Autogeek You can add a condition to your build stage. – Walter Feb 17 '21 at 01:46
  • @Walter I'm in a similar boat with the same question. Could you please give an example or elaborate more on the specific condition you would add to the build stage? – MAK Sep 03 '21 at 19:52