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.
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.
However I keep getting a 401 back from Netlify. I can confirm via POSTMAN that the access token is valid. So I'm not sure what I'm doing wrong here. Am I using the env variables incorrectly in the request?
here's the portion of the YAML file that deals with uploading the file.
- 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:
{"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
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'
azure curl azure-devops yaml netlify
add a comment |
I'm trying to upload a zip file to Netlify with a command line task using cURL on Azure DevOps.
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.
However I keep getting a 401 back from Netlify. I can confirm via POSTMAN that the access token is valid. So I'm not sure what I'm doing wrong here. Am I using the env variables incorrectly in the request?
here's the portion of the YAML file that deals with uploading the file.
- 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:
{"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
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'
azure curl azure-devops yaml netlify
If you do/did a write-up about how you did this, I would love to read about it. Looks like a pretty powerful static site build process using .Net and deployed to Netlify.
– talves
Dec 29 '18 at 16:10
1
@talves blizard.io/posts/…
– MrBliz
Dec 29 '18 at 16:17
thanks, simple and great example. github.com/MrBliz/blizard.io
– talves
Dec 29 '18 at 17:15
add a comment |
I'm trying to upload a zip file to Netlify with a command line task using cURL on Azure DevOps.
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.
However I keep getting a 401 back from Netlify. I can confirm via POSTMAN that the access token is valid. So I'm not sure what I'm doing wrong here. Am I using the env variables incorrectly in the request?
here's the portion of the YAML file that deals with uploading the file.
- 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:
{"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
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'
azure curl azure-devops yaml netlify
I'm trying to upload a zip file to Netlify with a command line task using cURL on Azure DevOps.
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.
However I keep getting a 401 back from Netlify. I can confirm via POSTMAN that the access token is valid. So I'm not sure what I'm doing wrong here. Am I using the env variables incorrectly in the request?
here's the portion of the YAML file that deals with uploading the file.
- 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:
{"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
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'
azure curl azure-devops yaml netlify
azure curl azure-devops yaml netlify
edited Dec 29 '18 at 11:11
MrBliz
asked Dec 28 '18 at 18:05
MrBlizMrBliz
2,77794674
2,77794674
If you do/did a write-up about how you did this, I would love to read about it. Looks like a pretty powerful static site build process using .Net and deployed to Netlify.
– talves
Dec 29 '18 at 16:10
1
@talves blizard.io/posts/…
– MrBliz
Dec 29 '18 at 16:17
thanks, simple and great example. github.com/MrBliz/blizard.io
– talves
Dec 29 '18 at 17:15
add a comment |
If you do/did a write-up about how you did this, I would love to read about it. Looks like a pretty powerful static site build process using .Net and deployed to Netlify.
– talves
Dec 29 '18 at 16:10
1
@talves blizard.io/posts/…
– MrBliz
Dec 29 '18 at 16:17
thanks, simple and great example. github.com/MrBliz/blizard.io
– talves
Dec 29 '18 at 17:15
If you do/did a write-up about how you did this, I would love to read about it. Looks like a pretty powerful static site build process using .Net and deployed to Netlify.
– talves
Dec 29 '18 at 16:10
If you do/did a write-up about how you did this, I would love to read about it. Looks like a pretty powerful static site build process using .Net and deployed to Netlify.
– talves
Dec 29 '18 at 16:10
1
1
@talves blizard.io/posts/…
– MrBliz
Dec 29 '18 at 16:17
@talves blizard.io/posts/…
– MrBliz
Dec 29 '18 at 16:17
thanks, simple and great example. github.com/MrBliz/blizard.io
– talves
Dec 29 '18 at 17:15
thanks, simple and great example. github.com/MrBliz/blizard.io
– talves
Dec 29 '18 at 17:15
add a comment |
1 Answer
1
active
oldest
votes
you need to use bash syntax to retrieve environment variable for that, not powershell (since you are using bash, not 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)
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
1
@MrBliz You need to update all of the references to correctly point to environment variables. For example,$(Build.BuildId)
should be$BUILD_BUILDID
. Refer to the documentation on variables. Same goes for$env:SITE_ID
-- that needs to be$SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.
– Daniel Mann
Dec 28 '18 at 19:05
1
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
1
@MrBliz I guarantee$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.
– Daniel Mann
Dec 28 '18 at 22:38
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962581%2fusing-environment-variables-in-a-curl-request-on-azure-devops%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you need to use bash syntax to retrieve environment variable for that, not powershell (since you are using bash, not 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)
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
1
@MrBliz You need to update all of the references to correctly point to environment variables. For example,$(Build.BuildId)
should be$BUILD_BUILDID
. Refer to the documentation on variables. Same goes for$env:SITE_ID
-- that needs to be$SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.
– Daniel Mann
Dec 28 '18 at 19:05
1
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
1
@MrBliz I guarantee$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.
– Daniel Mann
Dec 28 '18 at 22:38
|
show 4 more comments
you need to use bash syntax to retrieve environment variable for that, not powershell (since you are using bash, not 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)
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
1
@MrBliz You need to update all of the references to correctly point to environment variables. For example,$(Build.BuildId)
should be$BUILD_BUILDID
. Refer to the documentation on variables. Same goes for$env:SITE_ID
-- that needs to be$SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.
– Daniel Mann
Dec 28 '18 at 19:05
1
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
1
@MrBliz I guarantee$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.
– Daniel Mann
Dec 28 '18 at 22:38
|
show 4 more comments
you need to use bash syntax to retrieve environment variable for that, not powershell (since you are using bash, not 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)
you need to use bash syntax to retrieve environment variable for that, not powershell (since you are using bash, not 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)
answered Dec 28 '18 at 18:22
4c74356b414c74356b41
25.4k42051
25.4k42051
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
1
@MrBliz You need to update all of the references to correctly point to environment variables. For example,$(Build.BuildId)
should be$BUILD_BUILDID
. Refer to the documentation on variables. Same goes for$env:SITE_ID
-- that needs to be$SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.
– Daniel Mann
Dec 28 '18 at 19:05
1
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
1
@MrBliz I guarantee$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.
– Daniel Mann
Dec 28 '18 at 22:38
|
show 4 more comments
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
1
@MrBliz You need to update all of the references to correctly point to environment variables. For example,$(Build.BuildId)
should be$BUILD_BUILDID
. Refer to the documentation on variables. Same goes for$env:SITE_ID
-- that needs to be$SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.
– Daniel Mann
Dec 28 '18 at 19:05
1
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
1
@MrBliz I guarantee$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.
– Daniel Mann
Dec 28 '18 at 22:38
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
Thank you, but I still get the same response when I make the changes you suggest.
– MrBliz
Dec 28 '18 at 18:57
1
1
@MrBliz You need to update all of the references to correctly point to environment variables. For example,
$(Build.BuildId)
should be $BUILD_BUILDID
. Refer to the documentation on variables. Same goes for $env:SITE_ID
-- that needs to be $SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.– Daniel Mann
Dec 28 '18 at 19:05
@MrBliz You need to update all of the references to correctly point to environment variables. For example,
$(Build.BuildId)
should be $BUILD_BUILDID
. Refer to the documentation on variables. Same goes for $env:SITE_ID
-- that needs to be $SITE_ID
. You can print your environment variables to make sure you're accessing them correctly.– Daniel Mann
Dec 28 '18 at 19:05
1
1
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
well, i have no idea what is wrong with your request, but I'm showing you errors you have FOR SURE. or you can use debug mode, i think it prints all the variables you have @DanielMann
– 4c74356b41
Dec 28 '18 at 19:06
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
@DanielMann Those variable are being resolved correctly, that's not the issue.
– MrBliz
Dec 28 '18 at 19:09
1
1
@MrBliz I guarantee
$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.– Daniel Mann
Dec 28 '18 at 22:38
@MrBliz I guarantee
$(Build.BuildId)
isn't being resolved correctly in a bash script, because the build system replaces periods with underscores.– Daniel Mann
Dec 28 '18 at 22:38
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962581%2fusing-environment-variables-in-a-curl-request-on-azure-devops%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you do/did a write-up about how you did this, I would love to read about it. Looks like a pretty powerful static site build process using .Net and deployed to Netlify.
– talves
Dec 29 '18 at 16:10
1
@talves blizard.io/posts/…
– MrBliz
Dec 29 '18 at 16:17
thanks, simple and great example. github.com/MrBliz/blizard.io
– talves
Dec 29 '18 at 17:15