Use variable from Library in Azure DevOps for DOCKERFILE

Enrico Rossini 136 Reputation points
2021-02-03T09:21:31.017+00:00

I have a pipeline on Azure DevOps and this is the YAML file.

trigger:
- main

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: 'xxx'
  imageRepository: 'shinyproxyimage'
  containerRegistry: 'myrepo.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/DOCKERFILE'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          latest

Also, I have a DOCKERFILE and this is an example:

FROM openanalytics/r-base

LABEL maintainer "Enrico Rossini <enrico.rossini.uk@live.com>"

ARG project=testApp

# install Debian dependencies for R
RUN apt-get update && apt-get install -y \
    sudo \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev \
    libxml2-dev \
    libgit2-dev 

# packages needed renv and install
RUN R -e "install.packages(c('renv', 'devtools'), 
                           repos='https://cloud.r-project.org'); renv::consent(provided = TRUE)"
RUN R -e "install.packages('shiny', repos='http://cran.rstudio.com')"
RUN R -e "install.packages('shinydashboard', repos='http://cran.rstudio.com')"
RUN R -e "install.packages('shinythemes', repos='http://cran.rstudio.com')"

# create root folder for app in container
RUN mkdir /root/${project}

# copy the app to the image
COPY app /root/${project}

#COPY inst/shiny-server.conf /etc/shiny-server/shiny-server.conf

COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838

CMD ["R", "-e", "shiny::runApp('/root/testApp')"]

I want to use variables from the Library in both files (azure-pipeline.yml and DOCKERFILE). I saw this other post but there the guy is using a classic pipeline not a YAML file.

Is there a way to use variables from the library from Azure DevOps?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,264 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vaibhav Chaudhari 38,471 Reputation points
    2021-02-03T09:35:23.347+00:00

    Azure DevOps related questions are not supported on this forum. It's better to reach out to dedicated forum over here:

    https://developercommunity.visualstudio.com/spaces/21/index.html


    Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

    0 comments No comments