首页 > 解决方案 > Azure Devops handle special character in yaml

问题描述

I have problem with the Azure Devops yaml script, as it doesn't pick up my variable properly to build my ReactJS project. Below is the script, but somehow the build failed at git push, and the username does't get picked up

pool:
  vmImage: 'Ubuntu 16.04'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '9.8.0'
  displayName: 'Install Node.js'

- script: |
    npm install --no-save
    npm run build
    git push https://"$(azure.Username)":$(azure.Password)@$(azure.AppName).scm.azurewebsites.net:443/$(azure.AppName).git master
  displayName: 'npm install and build'

标签: azure-devops

解决方案


我的解决方案根据下面的 yml 文件,您可以将变量设置为在其中包含“$”符号。另一种更好的方法是使用 Azure DevOps 本身中的步骤。

image: node:9.8.0
clone:
  depth: full
pipelines:
  default:
    - step:
        script:
          - npm install --no-save
          - npm run build
          - git push https://$AZURE_LOGIN:$AZURE_PASSWORD@$AZURE_APP_NAME.scm.azurewebsites.net:443/$AZURE_APP_NAME.git master

推荐阅读