[[ Jenkins GitHub Authentication ]]

Jenkins

Jenkins GitHub Authentication

Настройка авторизации для доступа Jenkins к приватному репозиторию на GitHub'e.

Для доступа может использоваться логин и пароль пользователя либо personal access token и именно его будем использовать.

Установить plugin

Установить GitHub Authentication plugin в Jenkins'e

Создать personal access token

Используем инструкцию: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line

  • Нажимаем Generate token
  • Копируем токен, т.к. посмотреть его уже будет невозможно, только перегенерировать.

Проверим доступ к репозиторию по token'y

git clone https://github.com/user/repo.git
Клонирование в «repo»…
Username for 'https://github.com': <TOKEN>
Password for 'https://******@github.com': <ПАРОЛЬ ПУСТОЙ>
remote: Enumerating objects: 608, done.
remote: Counting objects: 100% (608/608), done.
remote: Compressing objects: 100% (310/310), done.
remote: Total 608 (delta 304), reused 512 (delta 220), pack-reused 0
Получение объектов: 100% (608/608), 90.63 KiB | 591.00 KiB/s, готово.                                                                                                                                             
Определение изменений: 100% (304/304), готово.

Добавить Credentials в Jenkins

Jenkins Pipeline GitHub+Maven

pipeline {
   agent any
   stages {
      stage('Build') {
        agent {
            docker {
                image 'maven:3-alpine'
                reuseNode true
            }
        }          
         steps {
            // Get some code from a GitHub repository
            git url: 'https://github.com/user/repo.git',
                branch: 'master',
                credentialsId: 'github_token'
 
            // Run Maven on a Unix agent.
            sh "mvn clean -Dtest=CucumberAllTest test"
         }
 
         post {
            // If Maven was able to run the tests, even if some of the test
            // failed, record the test results and archive the jar file.
            success {
               junit '**/target/surefire-reports/TEST-*.xml'
               archiveArtifacts 'target/*.jar'
            }
         }
      }
   }
}






Обсуждение

Ваш комментарий. Вики-синтаксис разрешён:
149 -9 = 
 
howto/jenkins/jenkins_github_auth.txt · Последнее изменение: 2022/08/31 14:53 — 127.0.0.1
Gentoo Linux Gentoo Linux Driven by DokuWiki