3.3. GitLab에서 Pipeline을 코드로 사용


조직 또는 프로젝트에서 GitLab을 기본 플랫폼으로 사용하는 경우 GitLab에서 Webhook가 있는 리포지토리의 코드로 Pipeline을 사용할 수 있습니다.

사전 요구 사항

  • Pipeline as Code가 클러스터에 설치되어 있는지 확인합니다.
  • 승인을 위해 GitLab에서 프로젝트 또는 조직 관리자로 개인 액세스 토큰을 생성합니다.

    참고
    • tkn pac CLI를 사용하여 Webhook를 구성하려면 admin:repo_hook 범위를 토큰에 추가합니다.
    • 특정 프로젝트에 토큰 범위를 사용하면 분기된 리포지토리에서 전송된 병합 요청(MR)에 대한 API 액세스를 제공할 수 없습니다. 이러한 경우 Code로 Pipeline은 파이프라인의 결과를 MR에 대한 주석으로 표시합니다.

프로세스

  1. Webhook를 구성하고 Repository CR(사용자 정의 리소스)을 생성합니다.

    • tkn pac CLI 툴을 사용하여 Webhook를 구성하고 리포지토리 CR을 자동으로 생성하려면 다음 명령을 사용합니다.

      $ tkn pac create repo
      Copy to Clipboard Toggle word wrap

      대화형 출력 샘플

      ? Enter the Git repository url (default: https://gitlab.com/owner/repo):
      ? Please enter the namespace where the pipeline should run (default: repo-pipelines):
      ! Namespace repo-pipelines is not found
      ? Would you like me to create the namespace repo-pipelines? Yes
      ✓ Repository repositories-project has been created in repo-pipelines namespace
      ✓ Setting up GitLab Webhook for Repository https://gitlab.com/owner/repo
      ? Please enter the project ID for the repository you want to be configured,
        project ID refers to an unique ID (e.g. 34405323) shown at the top of your GitLab project : 17103
      👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com
      ? Do you want me to use it? Yes
      ? Please enter the secret to configure the webhook for payload validation (default: lFjHIEcaGFlF):  lFjHIEcaGFlF
      ℹ ️You now need to create a GitLab personal access token with `api` scope
      ℹ ️Go to this URL to generate one https://gitlab.com/-/profile/personal_access_tokens, see https://is.gd/rOEo9B for documentation
      ? Please enter the GitLab access token:  **************************
      ? Please enter your GitLab API URL::  https://gitlab.com
      ✓ Webhook has been created on your repository
      🔑 Webhook Secret repositories-project has been created in the repo-pipelines namespace.
      🔑 Repository CR repositories-project has been updated with webhook secret in the repo-pipelines namespace
      ℹ Directory .tekton has been created.
      ✓ A basic template has been created in /home/Go/src/gitlab.com/repositories/project/.tekton/pipelinerun.yaml, feel free to customize it.
      Copy to Clipboard Toggle word wrap

    • Webhook를 구성하고 리포지토리 CR을 수동으로 생성하려면 다음 단계를 수행합니다.

      1. OpenShift 클러스터에서 Pipeline의 공용 URL을 코드 컨트롤러로 추출합니다.

        $ echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')
        Copy to Clipboard Toggle word wrap
      2. GitLab 프로젝트에서 다음 단계를 수행합니다.

        1. 왼쪽 사이드바를 사용하여 설정 -> Webhook 로 이동합니다.
        2. URL 을 코드 컨트롤러 공용 URL로 Pipeline으로 설정합니다.
        3. 웹 후크 시크릿을 추가하고 대체 위치에서 기록해 둡니다. 로컬 시스템에 openssl 을 설치하면 임의의 보안을 생성합니다.

          $ openssl rand -hex 20
          Copy to Clipboard Toggle word wrap
        4. 개별 이벤트 선택을 클릭하고 Commit comments,Issue comments,Pull request, Pushes 이벤트를 선택합니다.
        5. 변경 사항 저장을 클릭합니다.
      3. OpenShift 클러스터에서 개인 액세스 토큰 및 Webhook 시크릿을 사용하여 Secret 오브젝트를 생성합니다.

        $ oc -n target-namespace create secret generic gitlab-webhook-config \
          --from-literal provider.token="<GITLAB_PERSONAL_ACCESS_TOKEN>" \
          --from-literal webhook.secret="<WEBHOOK_SECRET>"
        Copy to Clipboard Toggle word wrap
      4. 리포지토리 CR을 생성합니다.

        예: 리포지토리 CR

        apiVersion: "pipelinesascode.tekton.dev/v1alpha1"
        kind: Repository
        metadata:
          name: my-repo
          namespace: target-namespace
        spec:
          url: "https://gitlab.com/owner/repo" # The repository URL
          git_provider:
            #url: "https://gitlab.example.com/" 
        1
        
            secret:
              name: "gitlab-webhook-config"
              key: "provider.token" # Set this if you have a different key in your secret
            webhook_secret:
              name: "gitlab-webhook-config"
              key: "webhook.secret" # Set this if you have a different key for your secret
        Copy to Clipboard Toggle word wrap

        1
        GitLab.com이 아닌 GitLab의 개인 인스턴스를 사용하는 경우 이 필드의 주석을 제거하고 GitLab API의 URL로 설정합니다. GitLab API는 리포지토리와 동일한 호스트입니다. 예를 들어 리포지터리가 https://gitlab.example.com/owner/repo 이면 API URL은 https://gitlab.example.com/ 입니다.
    참고
    • 코드로서의 파이프라인은 OpenShift Secret 오브젝트 및 Repository CR이 동일한 네임스페이스에 있다고 가정합니다.
  2. 선택 사항: 기존 리포지토리 CR의 경우 GitLab Webhook 보안을 여러 개 추가하거나 삭제된 보안을 대신 제공합니다.

    1. tkn pac CLI 툴을 사용하여 Webhook를 추가합니다.

      예: tkn pac CLI를 사용하여 추가 Webhook 추가

      $ tkn pac webhook add -n repo-pipelines
      Copy to Clipboard Toggle word wrap

      대화형 출력 샘플

      ✓ Setting up GitLab Webhook for Repository https://gitlab.com/owner/repo
      👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com
      ? Do you want me to use it? Yes
      ? Please enter the secret to configure the webhook for payload validation (default: AeHdHTJVfAeH):  AeHdHTJVfAeH
      ✓ Webhook has been created on repository owner/repo
      🔑 Secret owner-repo has been updated with webhook secert in the repo-pipelines namespace.
      Copy to Clipboard Toggle word wrap

    2. 기존 OpenShift Secret 오브젝트에서 webhook.secret 키를 업데이트합니다.
  3. 선택 사항: 기존 리포지토리 CR의 경우 개인 액세스 토큰을 업데이트합니다.

    • tkn pac CLI 툴을 사용하여 개인 액세스 토큰을 업데이트합니다.

      예: tkn pac CLI를 사용하여 개인 액세스 토큰 업데이트

      $ tkn pac webhook update-token -n repo-pipelines
      Copy to Clipboard Toggle word wrap

      대화형 출력 샘플

      ? Please enter your personal access token:  ****************************************
      🔑 Secret owner-repo has been updated with new personal access token in the repo-pipelines namespace.
      Copy to Clipboard Toggle word wrap

    • 또는 Repository CR을 수정하여 개인 액세스 토큰을 업데이트합니다.

      1. Repository CR에서 시크릿 이름을 찾습니다.

        ...
        spec:
          git_provider:
            secret:
              name: "gitlab-webhook-config"
        ...
        Copy to Clipboard Toggle word wrap
      2. oc patch 명령을 사용하여 $target_namespace 네임스페이스에서 $NEW_TOKEN 값을 업데이트합니다.

        $ oc -n $target_namespace patch secret gitlab-webhook-config -p "{\"data\": {\"provider.token\": \"$(echo -n $NEW_TOKEN|base64 -w0)\"}}"
        Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat