Set build number for conda metadata inside Azure pipeline

318 views Asked by At

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.

1

There are 1 answers

0
Stuart Berg On BEST ANSWER

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:

  • Use an environment variable:

    export CUSTOM_BUILD_NUMBER=123
    conda build foo-recipe
    

OR

  • Define the variable in conda_build_config.yaml (docs), as follows

    echo "CUSTOM_BUILD_NUMBER:" >> foo-recipe/conda_build_config.yaml
    echo " - 123"               >> foo-recipe/conda_build_config.yaml   
    
    conda build foo-recipe
    

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 %}