简体   繁体   中英

Publishing to Azure Web Apps from GitLab repository on trigger

I have a git repository in GitLab, which I need to publish to an Azure Web App on some arbitrary trigger (ie it must not trigger on every update to the repository, but we are fairly flexible on how we do trigger the publication). As far as I can see it, the easiest way to do this is to create an Azure Automation Powershell script that will be started somehow, and which will then authenticate to GitLab, pull the repository and publish it. However, I'm not sure how to trigger an arbitrary Powershell script without logging in to the Azure Management Portal, or how to get a deploy key for Azure to let it authenticate to Gitlab.

Are these solvable problems, or is there a better method?

UPDATE : Even better more up-to-date article is here: https://christianliebel.com/2016/05/auto-deploying-to-azure-app-services-from-gitlab/

Once you read and understand that one, then you can look at this for Azure and VSTS https://www.visualstudio.com/en-us/docs/build/get-started/aspnet-4-ci-cd-azure-automatic#faq

Older Answer: I came across this article, https://github.com/projectkudu/kudu/wiki/Continuous-deployment

The bottom area is the part that is most useful. It supposed to work on GitLab. Just to clear it up the Kudo service is already running on all of your azure web projects and should already be there. Just add the "scm" to the url to access it.

Ok bottom part of article here:

Set up a Web Hook so Kudu gets notified when a deployment happens

The hook URL is the /deploy path on the Kudu service. So it looks like https://mysite.scm.azurewebsites.net/deploy . But since the service uses basic auth, you need to pass the creds in the URL. Typically, you'll want to use the site-level credentials here and not the user credentials (see Deployment-credentials). So the full URL will look like https://$mysite:BigRandomPassword@mysite.scm.azurewebsites.net/deploy

The easiest way to get this URL is to directly copy it from the Azure Portal. You'll find it in the Configure tab, in the Deployment Trigger Url field.

Once you have the URL, you can set it as a GitHub/Bitbucket/GitLab hook.

For private repos, set up a deploy key

If the repo is private, you will also need to set up an SSH 'deploy key' on GitHub/Bitbucket/GitLab .

This can be done using the following steps:

Take the full deploy URL above, and replace /deploy with /api/sshkey?ensurePublicKey=1. So it'll look like https://$mysite:BigRandomPassword@mysite.scm.azurewebsites.net/api/sshkey?ensurePublicKey=1 Run curl on this URL, which returns an SSH public key. It's returned as a JSON string, so you'll need to remove the quotes. It should look like ssh-rsa AAAAB3NzaC1etc... Set this string as a 'deploy key' on your GitHub/Bitbucket/GitLab repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM