112 lines
4.3 KiB
Plaintext
112 lines
4.3 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
// {
|
|
// "object_kind": "push",
|
|
// "event_name": "push",
|
|
// "before": "3ce88aa51f204a7493c3f589eea68af67f55bdab",
|
|
// "after": "9759e8a6356535fb5dfd487b6809ae48bec4f01a",
|
|
// "ref": "refs/heads/main",
|
|
// "ref_protected": true,
|
|
// "checkout_sha": "9759e8a6356535fb5dfd487b6809ae48bec4f01a",
|
|
// "message": null,
|
|
// "user_id": 1,
|
|
// "user_name": "Administrator",
|
|
// "user_username": "root",
|
|
// "user_email": null,
|
|
// "user_avatar": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
|
|
// "project_id": 12,
|
|
// "project": {
|
|
// "id": 12,
|
|
// "name": "CICD_Test_Project",
|
|
// "description": null,
|
|
// "web_url": "http://git.cn/root/cicd_test_project",
|
|
// "avatar_url": null,
|
|
// "git_ssh_url": "git@git.cn:root/cicd_test_project.git",
|
|
// "git_http_url": "http://git.cn/root/cicd_test_project.git",
|
|
// "namespace": "Administrator",
|
|
// "visibility_level": 0,
|
|
// "path_with_namespace": "root/cicd_test_project",
|
|
// "default_branch": "main",
|
|
// "ci_config_path": null,
|
|
// "homepage": "http://git.cn/root/cicd_test_project",
|
|
// "url": "git@git.cn:root/cicd_test_project.git",
|
|
// "ssh_url": "git@git.cn:root/cicd_test_project.git",
|
|
// "http_url": "http://git.cn/root/cicd_test_project.git"
|
|
// },
|
|
// "commits": [
|
|
// {
|
|
// "id": "9759e8a6356535fb5dfd487b6809ae48bec4f01a",
|
|
// "message": "Update auto_test.txt",
|
|
// "title": "Update auto_test.txt",
|
|
// "timestamp": "2024-07-09T01:50:37+00:00",
|
|
// "url": "http://git.cn/root/cicd_test_project/-/commit/9759e8a6356535fb5dfd487b6809ae48bec4f01a",
|
|
// "author": {
|
|
// "name": "Administrator",
|
|
// "email": "admin@example.com"
|
|
// },
|
|
// "added": [],
|
|
// "modified": [
|
|
// "auto_test.txt"
|
|
// ],
|
|
// "removed": []
|
|
// }
|
|
// ],
|
|
// "total_commits_count": 1,
|
|
// "push_options": {},
|
|
// "repository": {
|
|
// "name": "CICD_Test_Project",
|
|
// "url": "git@git.cn:root/cicd_test_project.git",
|
|
// "description": null,
|
|
// "homepage": "http://git.cn/root/cicd_test_project",
|
|
// "git_http_url": "http://git.cn/root/cicd_test_project.git",
|
|
// "git_ssh_url": "git@git.cn:root/cicd_test_project.git",
|
|
// "visibility_level": 0
|
|
// }
|
|
// }
|
|
|
|
triggers {
|
|
GenericTrigger(
|
|
genericVariables: [
|
|
[key: 'GIT_COMMIT', value: '$.commits[0].id'],
|
|
[key: 'GIT_BRANCH', value: '$.ref'],
|
|
[key: 'GIT_COMMITTER_NAME', value: '$.commits[0].author.name'],
|
|
[key: 'GIT_COMMITTER_EMAIL', value: '$.commits[0].author.email'],
|
|
[key: 'GIT_COMMIT_MESSAGE', value: '$.commits[0].message'],
|
|
[key: "GIT_PROJECT_NAME", value: "$.project.name"]
|
|
],
|
|
causeString: 'Triggered on $GIT_BRANCH by $GIT_COMMITTER_NAME',
|
|
token: 'WEBHOOK_TOKEN',
|
|
printContributedVariables: true,
|
|
printPostContent: true,
|
|
regexpFilterText: '$GIT_BRANCH',
|
|
regexpFilterExpression: 'refs/heads/.*'
|
|
)
|
|
}
|
|
|
|
stages {
|
|
stage('Build') {
|
|
steps {
|
|
echo "Building on branch: ${env.GIT_BRANCH}"
|
|
echo "Commit by: ${env.GIT_COMMITTER_NAME} <${env.GIT_COMMITTER_EMAIL}>"
|
|
echo "Commit message: ${env.GIT_COMMIT_MESSAGE}"
|
|
echo "Commit hash: ${env.GIT_COMMIT}"
|
|
echo "Project Name: ${env.GIT_PROJECT_NAME}"
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
success{
|
|
// echo "Success"
|
|
sh "/usr/bin/python3.6 ~/scripts/notify.py 'finish' '${env.GIT_BRANCH}' '${env.GIT_COMMITTER_NAME}' '${env.GIT_COMMIT_MESSAGE}' '${env.GIT_COMMIT}' '${env.GIT_PROJECT_NAME}' 'success'"
|
|
}
|
|
failure {
|
|
// echo "Failure"
|
|
sh "/usr/bin/python3.6 ~/scripts/notify.py 'finish' '${env.GIT_BRANCH}' '${env.GIT_COMMITTER_NAME}' '${env.GIT_COMMIT_MESSAGE}' '${env.GIT_COMMIT}' '${env.GIT_PROJECT_NAME}' 'failure'"
|
|
}
|
|
always {
|
|
// echo "Always"
|
|
}
|
|
}
|
|
}
|