안심하세요 - API 테스트 예제 API에서 보안 자격 증명을 사용하여 Jenkins 파이프라인을 생성하고 실행하는 방법 - GitHub API - GitHub 리포지토리 생성 https://docs.github.com/en/rest/repos?apiVersion=2022-11-28 인증된 사용자를 위한 리포지토리 생성 1) 직접 API 토큰으로 API 테스트 생성 2) 이제 Jenkins에 토큰을 안전하게 저장 3) 프로젝트에서 Jenkinsfile을 생성하고 Jenkinsfile 내에서 보안 토큰 사용 4) 이제 Java 자동화 프레임워크에서 보안 토큰을 사용합니다. 5) API 테스트 프로젝트를 GitHub에 푸시합니다. 6) Jenkins에서 파이프라인 작업을 생성하고 실행합니다. 7) Jenkins가 실행 중에 환경 변수로 토큰을 삽입합니다. Jenkins에 토큰을 안전하게 저장하는 방법 ------------- Jenkins 관리 → 자격 증명 → (글로벌) → 자격 증명 추가 선택: 종류: 비밀 텍스트 비밀: your_api_token_here ID: api-token 설명: 자동화를 위한 API 토큰 지금 저장을 클릭합니다. Jenkins는 토큰을 암호화하여 안전하게 저장합니다. Jenkinsfile 내에서 자격 증명(토큰)을 사용하는 방법 ------------------------------------- 파이프라인 { 에이전트 모든 단계 { stage('Checkout Code') { steps { git Branch: 'main', url: 'https://github.com/tricity-selenium/TodenDemoTest.git' } } stage('API 테스트 실행') { steps { withCredentials([string(credentialsId: 'api-token'), 변수: 'TOKEN')]) { bat 'mvn clean test' } } } } post { Always { junit 'target/surefire-reports/*.xml' } } } 여기 파이프라인에서 무슨 일이 일어나고 있는지 ---------------------- | 부품 | 의미 | | --------------- | ----------------- | | `credentialsId: 'api-token'` | Jenkins에서 제공한 ID | | `변수: '토큰'` | 임시 환경 변수 | | `withCredentials()` | 보안 블록 | | `bat 'mvn clean test'` | 테스트 실행 | Jenkins는 자동으로: 토큰을 환경 변수로 주입합니다. 콘솔 로그에 토큰 마스크 Java 자동화 프레임워크에서 사용하는 방법 --------------------- String token = System.getenv("TOKEN"); been() .header("Accept", "application/vnd.github+json") .header("Authorization", "Bearer "+ token) .header("X-GitHub-Api-Version", "2022-11-28") 프로젝트 코드는 다음 GitHub 리포지토리에서 사용할 수 있습니다. https://github.com/tricity-selenium/TokenDemoRep #apitesting #restassured #apitestingwithrestassured #automationtesting #restassuredtutorials #qatraining #letslearnqa #jenkinspipeline