This repository was archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpython.groovy
130 lines (119 loc) · 3.47 KB
/
python.groovy
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import com.concur.*;
workflowDoc = '''
title: Python
overview: Run Python scripts.
additional_resources:
- name: Docker images
url: https://hub.docker.com/_/python/
tools:
- type: String
name: buildImage
description: Docker image containing Python and any non requirements.txt dependencies.
required: true
- type: String
name: binary
description: The Python binary to use, for example `python2` or `python3`.
required: false
default: python
- type: String
name: file
description: Path to a script to run, relative to the root of the project.
required: true
- type: String
name: requirements
description: Path to a requirements.txt file to install via Pip.
default: requirements.txt
required: false
- type: List
name: arguments
description: List of arguments to the script, should include any flags if needed.
required: false
full_example: |
pipelines:
tools:
python:
buildImage: "python:3.6-alpine3.7"
branches:
patterns:
feature: .+
branches:
feature:
steps:
- python:
- script:
file: scripts/build.py
'''
concurPipeline = new Commands()
concurUtil = new Util()
/*
description: Run a Python script.
parameters:
- type: String
name: buildImage
description: Docker image containing Python and any non requirements.txt dependencies.
required: true
- type: String
name: binary
description: The Python binary to use, for example `python2` or `python3`.
required: false
default: python
- type: String
name: file
description: Path to a script to run, relative to the root of the project.
required: true
- type: String
name: requirements
description: Path to a requirements.txt file to install via Pip.
default: requirements.txt
required: false
- type: List
name: arguments
description: List of arguments to the script, should include any flags if needed.
required: false
example: |
branches:
feature:
steps:
- python:
# Simple
- script:
# Advanced
- script:
binary: python3
script: scripts/update_docs.py
*/
public script(Map yml, Map args) {
String dockerImage = args?.buildImage ?: yml.tools?.python?.buildImage
String pythonBin = args?.binary ?: yml.tools?.python?.binary ?: 'python'
String file = args?.file ?: yml.tools?.python?.file
String requirements = args?.requirements ?: yml.tools?.python?.requirements
List arguments = args?.arguments ?: yml.tools?.python?.arguments
String pythonCommand = "$pythonBin $file"
if (arguments) {
pythonCommand = "$pythonCommand ${arguments.join(' ')}"
}
def requirementsFileExists = fileExists(requirements)
dockerImage = concurUtil.mustacheReplaceAll(dockerImage)
pythonCommand = concurUtil.mustacheReplaceAll(pythonCommand)
docker.image(dockerImage).inside {
if (requirementsFileExists) {
pythonCommand = "pip install -r $requirements && $pythonCommand"
}
sh "$pythonCommand"
}
}
/*
* Set the name of the stage dynamically.
*/
public getStageName(Map yml, Map args, String stepName) {
switch(stepName) {
case 'script':
String file = args?.file ?: yml.tools?.python?.file
return "python: script: $file"
}
}
public tests(Map yml, Map args) {
String workflowName = 'python'
println "Testing $workflowName"
}
return this;