conda-buildazure-devops-pipelines

Set build number for conda metadata inside Azure pipeline


I am using the bash script to build the conda pakage in azure pipeline conda build . --output-folder $(Build.ArtifactStagingDirectory) And here is the issue, Conda build uses the build number in the meta.yml file(see here).

A solution of What I could think of is, first, copy all files to Build.ArtifactStagingDirectory and add the Azure pipeline's Build.BuildNumber into the meta.yml and build the package to Build.ArtifactStagingDirectory (within a sub-folder)

I am trying to avoid do it by writing shell script to manipulate the yaml file in Azure pipeline, because it might be error prone. Any one knows a better way? Would be nice to read a more elegant solution in the answers or comments.


Solution

  • I don't know much about Azure pipelines. But in general, if you want to control the build number without changing the contents of meta.yaml, you can use a jinja template variable within meta.yaml.

    Choose a variable name, e.g. CUSTOM_BUILD_NUMBER and use it in meta.yaml:

    package:
      name: foo
      version: 0.1
    
    build:
      number: {{ CUSTOM_BUILD_NUMBER }}
    

    To define that variable, you have two options:

    OR


    If you want, you can add an if statement so that the recipe still works even if CUSTOM_BUILD_NUMBER is not defined (using a default build number instead).

    package:
      name: foo
      version: 0.1
    
    build:
      {% if CUSTOM_BUILD_NUMBER is defined %}
        number: {{ CUSTOM_BUILD_NUMBER }}
      {% else %}
        number: 0
      {% endif %}