File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ import requests
4
+
5
+ from invoke import task
6
+
7
+
8
+ API_URL = 'https://ci.appveyor.com/api'
9
+ TOKEN = os .environ ["APPVEYOR_API_TOKEN" ]
10
+ ACCOUNT_NAME = "lukasa"
11
+ PROJECT_NAME = "certitude"
12
+ BASE_URL = "https://ci.appveyor.com/api"
13
+
14
+
15
+ @task
16
+ def download_artifacts (build_id ):
17
+ s = requests .Session ()
18
+ s .headers = {
19
+ "Authorization" : "Bearer {}" .format (TOKEN )
20
+ }
21
+
22
+ # Get project build details.
23
+ print "Obtaining artifacts for {}" .format (PROJECT_NAME )
24
+ build_details_url = BASE_URL + "/projects/{}/{}/build/{}" .format (
25
+ ACCOUNT_NAME , PROJECT_NAME , build_id
26
+ )
27
+ r = s .get (build_details_url , stream = True )
28
+ r .raise_for_status ()
29
+
30
+ for job in r .json ()[u'build' ][u'jobs' ]:
31
+ # Get the artifact list because we don't know what the filename is.
32
+ job_id = job [u'jobId' ]
33
+ artifacts_url = BASE_URL + "/buildjobs/{}/artifacts/" .format (job_id )
34
+
35
+ print "Artifacts for {}" .format (job_id )
36
+ r = s .get (artifacts_url , stream = True )
37
+ r .raise_for_status ()
38
+
39
+ artifact_name = r .json ()[0 ][u'fileName' ]
40
+ artifact = BASE_URL + "/buildjobs/{}/artifacts/{}" .format (
41
+ job_id , artifact_name
42
+ )
43
+
44
+ print "Downloading {} to {}" .format (artifact , artifact_name )
45
+ r = s .get (artifact , stream = True )
46
+ r .raise_for_status ()
47
+
48
+ with open ("{}" .format (artifact_name ), 'wb' ) as f :
49
+ for chunk in r .iter_content (4096 ):
50
+ f .write (chunk )
You can’t perform that action at this time.
0 commit comments