1
votes

Hello guys am new with Gitlab and Azure , currently am having a repo on Gitlba and am trying to deploy it to Azure, but I can't manage to achieve this, tried to follow this link , but the information is old, Is there anyone with a latest link or resource to achieve this?

Thanks

2

2 Answers

1
votes

The UI of the azure portal and the GitLab have changed, but the steps are still similar.

The link in the comment is helpful, I test it and works fine. In order to prevent the link from failing in the future, I made some summary as below.

1.In the web app in the portal -> Deployment Center -> External -> App Service build service -> write the information as below -> next to finish.

enter image description here

The Repository you can get via the Clone button in your GitLab project, the Username and Password is the ones of your GitLab account.

enter image description here

2.In your GitLab -> Settings -> Repository -> Deploy Keys -> Expand -> Add the key of the one in the https://<webapp-name>.scm.azurewebsites.net/api/sshkey?ensurePublicKey=1(ssh-rsa xxxxxx). Then you could test the Sync in the Deployment Center in the portal, it should work.

3.Then we config the continuous deployment, in your GitLab -> Settings -> Integrations -> write the URL ( you can get it in the web app -> Properties -> Deployment Trigger URL ) -> Add webhook.

4.Then I create a new file in the GitLab project, it deploys to the web app automatically.

enter image description here

2
votes

Joy's answer above is helpful. I've rewritten it to clarify the steps on obtaining a SSH 'deploy key'.

  1. Head over to your Gitlab repository and click the Clone button. Copy the Clone with SSH address.

    Gitlab Repository Clone Button

    Also, have your Gitlab account username and password available.

  2. In the Azure portal go to your web app resource and go to the Deployment Center. Choose the External option. We're going to use the 'App Service build service'. Next enter in the data from step 1. Click Continue to finish.

    Enter the data from step 1

  3. Next we're going to get the SSH 'deploy key'.

    1. First go to the Properties page and copy the Deployment Trigger Url field.
    2. Go back to the Deployment Center and click the Credentials button.
    3. Insert these credentials into your copied url, like so: https://$mysite:[email protected]/deploy
    4. Take the full deploy URL above, and replace /deploy with /api/sshkey?ensurePublicKey=1. So it'll look like: https://$mysite:[email protected]/api/sshkey?ensurePublicKey=1
    5. 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...
      Copy the key.

    (These steps are from the Kudu docs)

  4. In GitLab go to Settings -> Repository -> Deploy Keys and click Expand. Add a title and the SSH 'deploy key' here. Then save. Test it by going back to the Deployment Center in the Azure portal and clicking the Sync button. It should work.

    Adding deploy key to Gitlab

  5. Then we'll configure the continuous deployment. In your GitLab go to Settings -> Integrations -> write the URL (This is the same Deployment Trigger URL in Properties we used earlier) To save click the Add webhook button.

    Add Gitlab Integration

  6. Create a new file (or commit a change) in the GitLab project and it deploys to the web app automatically.