高枕无忧 - 如何在 API 测试示例中使用安全凭证创建和运行 Jenkins 管道 API - 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 中使用凭证(令牌) -------------------------------------------------- pipeline { agent any stage { stage('Checkout Code') { Steps { git Branch: 'main', url: 'https://github.com/tricity-selenium/TodenDemoTest.git' } } stage('Run API Tests') { steps { withCredentials([string(credentialsId: 'api-token', variable: 'TOKEN')]) { bat 'mvn clean test' } } } } post { always { junit 'target/surefire-reports/*.xml' } } } 管道中发生了什么 -------------------------------------------------- |部分|意义| | ---------------------------- | ------------------------------------------ | | `credentialsId:'api-token'` |您在 Jenkins 中提供的 ID | | `变量:'令牌'` |临时环境变量 | | `withCredentials()` |安全区块 | | `bat 'mvn clean 测试'` |运行您的测试 | Jenkins 自动: 将令牌作为环境变量注入 在控制台日志中屏蔽令牌 如何在 Java 自动化框架中使用它 ---------------------------------------------- String token = System.getenv("TOKEN");给定() .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
免责声明:info@kdj.com
所提供的信息并非交易建议。根据本文提供的信息进行的任何投资,kdj.com不承担任何责任。加密货币具有高波动性,强烈建议您深入研究后,谨慎投资!
如您认为本网站上使用的内容侵犯了您的版权,请立即联系我们(info@kdj.com),我们将及时删除。