[英]Using Environment Variables in a cURL request on Azure Devops
I'm trying to upload a zip file to Netlify with a command line task using cURL on Azure DevOps. 我正在尝试使用Azure DevOps上的cURL通过命令行任务将zip文件上传到Netlify。
Obviously I don't want to have my Netlify access token in the yaml file, so I've created a secret variable for it (using the UI designer) and mapped it using the syntax in the docs . 显然,我不想在yaml文件中使用Netlify访问令牌,因此我已经为其创建了一个秘密变量(使用UI设计器),并使用docs中的语法对其进行了映射。
However I keep getting a 401 back from Netlify. 但是我一直从Netlify获得401。 I can confirm via POSTMAN that the access token is valid. 我可以通过POSTMAN确认访问令牌有效。 So I'm not sure what I'm doing wrong here. 所以我不确定我在做什么错。 Am I using the env variables incorrectly in the request? 我在请求中错误地使用了env变量吗?
here's the portion of the YAML file that deals with uploading the file. 这是YAML文件中用于上传文件的部分。
- script: >-
curl
-H 'Authorization: Bearer $env:ACCESS_TOKEN'
-H 'Content-Type: application/zip'
--data-binary '@$(Build.BuildId).zip'
https://api.netlify.com/api/v1/sites/$env:SITE_ID/deploys
workingDirectory: '$(Build.ArtifactStagingDirectory)'
displayName: 'Upload to Netlify'
env:
ACCESS_TOKEN: $netlifyAccessToken
SITE_ID: $netlifySiteId
Response from Netlify: Netlify的回复:
{"code":401,"message":"Access Denied: Origin returned bad status 401"}`
EDIT: 编辑:
Below is the full YAML file after I managed to get it working using the 'input-macro' syntax from the docs 以下是我设法使用文档中的“ input-macro”语法使其正常工作后的完整YAML文件
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
configuration: debug
platform: x64
steps:
- task: DotNetCoreInstaller@0
displayName: Install .NET Core SDK
name: install_dotnetcore_sdk
enabled: true
inputs:
packageType: 'sdk'
version: '2.2.101'
- script: dotnet tool install -g Wyam.Tool
displayName: Install Wyam
- script: wyam
displayName: Build Site
- task: ArchiveFiles@2
displayName: Zip Site
inputs:
rootFolderOrFile: '$(Agent.BuildDirectory)/s/output'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- script: >-
curl
-H 'Authorization: Bearer $(netlifyAccessToken)'
-H 'Content-Type: application/zip'
--data-binary '@$(Build.BuildId).zip'
https://api.netlify.com/api/v1/sites/$(netlifySiteId)/deploys
workingDirectory: '$(Build.ArtifactStagingDirectory)'
displayName: 'Upload to Netlify'
you need to use bash syntax to retrieve environment variable for that, not powershell (since you are using bash, not powershell): 您需要使用bash语法来检索环境变量,而不是powershell(因为您正在使用bash,而不是powershell):
-H "Authorization: Bearer $ACCESS_TOKEN"
I also suspect that you need to update your env declaration: 我也怀疑您需要更新环境声明:
env:
ACCESS_TOKEN: $(netlifyAccessToken) << ADO token to replace with variable from build scope
SITE_ID: $(netlifySiteId)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.