Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
A background
1.1 requirements
The code submitted by the developer cannot be automatically associated with the story or task on tapD. The submitted merge request needs to be manually associated with the ID on TAPD, and a valid record and sum cannot be formed
Tapd and GitLab need linkage, TAPD provides source submission trend, and automatically associated submission.
After the completion of Gitlab CI, configure message notification, detect server abnormalities, and notify the pipeline status.
1.2 scenario
- Gitlab commit code with commit number is associated with graphical presentation on TAPD
- Tapd pipeline integration Enterprises use continuous integration platforms to visualize continuous integration platform data in the TAPD pipeline.
- Notify the assembly line through the wechat robot of the enterprise.
Two Gitlab configuration
2.1 Obtaining Webhook Information
- Application Configuration in Tapd’s project -> Add Application ->Gitlab source code
- Enable Secret Token and obtain the Webhook URL and project Token
Enterprise project webhook:
Webhook URL:https://www.tapd.cn/hook/index/67xxxxx24/6930c28xxxxxxxxxxxxxxxx
Secret Token:af07d3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Copy the code
When GitLab submits code, notifications can be sent to TAPD via POST requests.
2.2 Associating Gitlab CI
- Integrate TAPD in the Gitlab project
Add Webhook in Project -> Settings -> Integration.
Three Tapd configuration pipeline
3.1 Code Association
3.2 Continuous integration association
TAPD supports associated Jenkins, Gitlab CI and other tool platforms. By contacting TAPD, you can view the scope, results, and build history of a given build task in TAPD.
3.3 Code quality analysis
TAPD supports associating with mainstream code detection tools. The detection tool that the team is using can be associated with TAPD, and the result of each code scan can be viewed through TAPD pipeline for problem tracking and resolution.
Code quality checks depend on the associated continuous integration services. Take Jenkins as an example, SonarQube service and plug-in are installed in Jenkins, and SonarQube steps are configured in associated construction tasks, and the quality analysis data can be viewed through TAPD pipeline.
3.4 Product Management
Artifact/package management relies on associated continuous integration services. Take Jenkins as an example, by installing the Nexus plug-in in Jenkins, the information of each build artifact can be displayed in the TAPD pipeline by adding the Nexus Repository Manager Publisher step in the build task.
3.5 Automated Tests
Automated test execution relies on associated continuous integration services. Taking Jenkins as an example, automatic test steps are configured in Jenkins construction task, and “TAPD Automated test Report analysis” task is added in post-construction step, and automatic test result file path is filled in, so use case execution and test report can be viewed in TAPD pipeline.
3.6 Releasing deployment
Deployment publishing depends on associated continuous integration services. Take Jenkins as an example, install Ansible plug-in in Jenkins and view deployment release information in TAPD pipeline by adding the Invoke Ansible Playbook step in the build task.
After the integration is completed, gitLab and TAPD can be linked to jump to the code submission page corresponding to GitLab from TAPD.
Note: Specification when submitting code:
#Write your own changes first:
fix: fix a bug
---
#Copy the source submission key in the story- story = 10 xxxx70 - user = kaliarch [example] father requirements at https://www.tapd.cn/48xxxxx5/s/1xxxxxCopy the code
Submit code in GitLab and view pipeline details in TapD:
Iv GitLab CI is notified by the wechat robot of the enterprise
4.1 Obtain the enterprise wechat robot Webhook
You can build the message in the last step through the enterprise wechat bot notification.
You can first pull the r&d staff from the wechat group of the enterprise, and then pull the robot from the group through mobile phone operation, and then notify the robot during construction.
The webhook of the robot is as follows:
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=777c9exxxxxxxxxxxxxxxxxxxxxxxxxx5c
Copy the code
4.2 Gitlab configures the robot Webhook
In order to ensure the security of wechat robot Webhook, it is configured in the environment variables of the group, which is convenient for reference in CI.
4.3 Integrate notifications in Gitlab CI
Thanks to the use of the GitLab shared template library, the integration is very easy and can be done only in the Check Job of GitLabci-Templates
.check: script: - echo -e "\033[5;35; 40m check ${APP_NAME} in k8s ${DEPLOY_ENV} environment status... \033[0m" - kubectl rollout status -w --timeout=300s deployment/${APP_NAME}-deploy -n ${NAMESPACE} && curl ${WECHAT_WEBHOOK} -H 'Content-Type:application/json' -d "{\" msgtype \ ": \" markdown \ ", \ "markdown \" : {\ "content \" : \ "${PROJECT_NAME} project build results: < font color = \ \" info \ \ "> success < / font > \ n > by the building: $GITLAB_USER_NAME triggers \ N > Project name: $CI_PROJECT_NAME\n> Commit number: $CI_COMMIT_SHA\n> Commit log: $CI_COMMIT_MESSAGE\n> Build branch: $CI_COMMIT_REF_NAME \ n > image information: ${REGISTRY} / ${NAMESPACE} / ${APP_NAME} : ${APP_TAG} \ n > line address: [$CI_PIPELINE_URL]($CI_PIPELINE_URL)\"}}" || curl ${WECHAT_WEBHOOK} -H 'Content-Type:application/json' -d "{\" msgtype \ ": \" markdown \ ", \ "markdown \" : {\ "content \" : \ "${PROJECT_NAME} the build results of the project: <font color=\\"warning\\"> Failed </font>\n> This build is triggered by: $GITLAB_USER_NAME \n> Project name: $CI_PROJECT_NAME\n> Commit number: $CI_COMMIT_SHA\n> Commit log: $CI_COMMIT_MESSAGE\n> Build branch :$CI_COMMIT_REF_NAME\n> Mirror information :${REGISTRY}/${NAMESPACE}/${APP_NAME}:${APP_TAG}\n> Pipeline address: [$CI_PIPELINE_URL]($CI_PIPELINE_URL)\"}}" retry: max: 1 when: - always allow_failure: trueCopy the code
Five Matters needing attention
- When configuring Webhooks generated in the source integration above TAPD into GitLab, they cannot be configured in the gitLab group integration and need to be configured in the individual projects involved.
- The TAPD task, in conjunction with GitLab, needs to copy the source submission key when submitting code.
The resources
- Work.weixin.qq.com/api/doc/900…