Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Jenkinsfile 4.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  1. /* groovylint-disable CompileStatic, DuplicateMapLiteral, DuplicateStringLiteral, LineLength, NestedBlockDepth */
  2. pipeline {
  3. agent any
  4. environment {
  5. JENKINS_USER_NAME = 'Jenkins'
  6. JENKINS_EMAIL = 'jenkins-poc@dagshub.com'
  7. GIT_REPO = 'dagshub.com/Guy/stackexchange-data-pr'
  8. GIT_COMMIT_REV = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
  9. }
  10. stages {
  11. stage('Run inside Docker Image') {
  12. when { anyOf { branch 'master'; changeRequest() } }
  13. agent {
  14. dockerfile {
  15. additionalBuildArgs '--tag stackexchange-data-pr:$BRANCH_NAME'
  16. args '-v $WORKSPACE:/project -w /project -v dvc_cache:/dvc_cache -e PYTHONPATH=/project'
  17. }
  18. }
  19. stages {
  20. stage('Setup DVC and Mlflow Creds') {
  21. steps {
  22. withCredentials(
  23. [
  24. usernamePassword(
  25. credentialsId: '0814fb52-0edc-4569-9cd4-798c9cf62b40',
  26. passwordVariable: 'PASSWORD',
  27. usernameVariable: 'USER_NAME'),
  28. ]
  29. ) {
  30. sh '''
  31. dvc remote modify origin --local auth basic
  32. dvc remote modify origin --local user $USER_NAME
  33. dvc remote modify origin --local password $PASSWORD
  34. dvc status -r origin
  35. echo "export MLFLOW_TRACKING_USERNAME=$USER_NAME" > .env
  36. echo "export MLFLOW_TRACKING_PASSWORD=$PASSWORD" >> .env
  37. '''
  38. }
  39. }
  40. }
  41. stage('Sync DVC Remotes') {
  42. steps {
  43. sh '''
  44. dvc remote add --local jenkins_local /dvc_cache
  45. dvc status
  46. dvc status -r jenkins_local
  47. dvc status -r origin
  48. dvc pull -r jenkins_local || echo 'Some files are missing in local cache!'
  49. dvc pull -r origin
  50. dvc push -r jenkins_local
  51. '''
  52. }
  53. }
  54. stage('Update DVC Pipeline') {
  55. when { changeRequest() }
  56. steps {
  57. sh '''
  58. dvc repro --dry -P
  59. dvc repro -P
  60. git branch -a
  61. cat dvc.lock
  62. dvc push -r jenkins_local
  63. dvc push -r origin
  64. '''
  65. }
  66. }
  67. stage('Commit back results') {
  68. when { changeRequest() }
  69. steps {
  70. withCredentials(
  71. [
  72. usernamePassword(
  73. credentialsId: '0814fb52-0edc-4569-9cd4-798c9cf62b40',
  74. passwordVariable: 'GIT_PAT',
  75. usernameVariable: 'GIT_USER_NAME'),
  76. ]
  77. ) {
  78. sh '''
  79. git branch -a
  80. git status
  81. if ! git diff --exit-code dvc.lock; then
  82. git add .
  83. git status
  84. git config --local user.email $JENKINS_EMAIL
  85. git config --local user.name $JENKINS_USER_NAME
  86. git commit -m "$GIT_COMMIT_REV: Update dvc.lock and metrics"
  87. git push https://$GIT_USER_NAME:$GIT_PAT@$GIT_REPO HEAD:$CHANGE_BRANCH
  88. else
  89. echo 'Nothing to Commit!'
  90. fi
  91. '''
  92. }
  93. }
  94. }
  95. stage('Deploy model to production') {
  96. when { branch 'master' }
  97. steps {
  98. sh '''
  99. echo "Deploying to production...."
  100. '''
  101. }
  102. }
  103. }
  104. post {
  105. always {
  106. sh '''
  107. rm -f .env || echo '.env not found! Nothing to worry about!'
  108. rm -f .dvc/config.local || echo 'Config not found! Nothing to worry about!'
  109. '''
  110. }
  111. }
  112. }
  113. }
  114. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...