简体   繁体   中英

Is it possible to checkout Gitlab repository in YML which sits in Github?

So I'm trying to learn deployement with Azure Devops. I have this Angular app sitting in Gitlab which already has a CI/CD pipeline with jenkins to kubernetes cluster. So i was thinking to do the same with Azure Devops via YAML. Which is not possible according to Azure docs directly from gitlab.

So what i'm trying to do is create CI pipeline from github which takes checkout from gitlab UI repo and build it for deployement.

I have created a Repository Resource in my below pipeline YAMl file. Azure give me error saying:

Repository JpiPipeline references endpoint https://gitlab.com/myusername/myUiRepo.git which does not exist or is not authorized for use

trigger:
  - master


resources:
  repositories:
  - repository: UiPipeline.  #alias
    type: git
    name: repository_name
    # ref: refs/heads/master  # ref name to use; defaults to 'refs/heads/master'
    endpoint: https://@gitlab.com/myusername/myUiRepo.git   # <-- Is this possible


stages:
- stage: Checkout
  jobs:
  - job: Build
    pool:
      vmImage: 'Ubuntu-16.04'
    continueOnError: true
    steps:
    - checkout: JpiPipeline
    - script: echo "hello to my first Build"

Repository type gitlab is not support in YAML pipeline yet. The currently supported types are git, github, and bitbucket, see supported types .

The workaround to get the gitlab repo sources is to run git command inside the script tasks.

For below example Yaml pipeline:

- checkout: none to avoid checkout the github source.

Use git clone https://username:password@gitlab.com/useraccount/reponame.git to clone the gitlab repo inside a script task.

stages:
- stage: Checkout
  jobs:
  - job: Build
    pool: 
      vmImage: 'Ubuntu-latest'
    steps:
    - checkout: none
    - script: | 
        git clean -ffdx
        git clone  https://username:password@gitlab.com/useraccount/reponame.git
         #if your password or username contain @ replace it with %40

Your gitlab repo will be clone to folder $(system.defaultworkingdirectory)/reponame

Another workaround is to classic UI pipeline. Gitlab repo type is supported in Classic UI pipeline.

You can choose Use the classic editor to create a classic ui pipeline.

在此处输入图像描述

When you come to select source page. Choose other git and click Add connection to add your gitlab repo url. Then the pipeline will get the sources for your gitlab repo.

在此处输入图像描述

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