0

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.

SLN
  • 4,772
  • 2
  • 38
  • 79
  • Why do you want to change the build number programmatically? The build number is intended to be incremented when you make changes to the recipe contents, such as the requirements in `meta.yaml` or the commands in `build.sh`. I don't understand why you want the conda package build number to match the Azure pipelines build number. – Stuart Berg Dec 10 '20 at 05:19

1 Answers1

1

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 %}
Stuart Berg
  • 17,026
  • 12
  • 67
  • 99