Skip to content

Commit ebc49ab

Browse files
Got the jenkins script running
1 parent 1c84d08 commit ebc49ab

2 files changed

Lines changed: 43 additions & 24 deletions

File tree

bin/buildAndDeploy.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def runTests() -> None:
6060
# We can't use the `| grep -v "fixtures" | grep -v "vendor"` stuff because working with pipes in
6161
# subprocess is tricky, doing this is easier to me.
6262
go_mods = ['go', 'list', './...']
63-
print(f"[turquoise2]Running:" + " ".join(go_mods))
63+
print(f"[turquoise2]Running: " + " ".join(go_mods))
6464
mods = subprocess.run(go_mods, capture_output=True, check=True, text=True)
6565
clean_mods = []
6666
for mod in mods.stdout.split("\n"):
@@ -72,11 +72,11 @@ def runTests() -> None:
7272
print(f'[turquoise2]Running: go vet $(go list ./... | grep -v "fixtures" | grep -v "vendor")')
7373
subprocess.run(go_vet, check=True)
7474
go_test = ['go', 'test'] + clean_mods
75-
print(f'[turquoise2]Running: ' + " ".join(go_test))
75+
print(f'[turquoise2]Running: go test $(go list ./... | grep -v "fixtures" | grep -v "vendor")')
7676
subprocess.run(go_test, check=True)
7777
go_sec = ['gosec', '-exclude-dir=fixture', '-exclude-dir=plugin/resources', '-quiet', './...']
7878
# Not using the 'real' command because this is more copy/pasteable.
79-
print(f'[turquoise2]Running: go test $(go list ./... | grep -v "fixtures" | grep -v "vendor")')
79+
print('[turquoise2]Running: ' + " ".join(go_sec))
8080
try:
8181
subprocess.run(go_sec, check=True)
8282
except FileNotFoundError:
@@ -286,15 +286,28 @@ def getChecksums(self) -> dict:
286286
return checksums
287287

288288
def runJenkins(self):
289-
"""https://github.ibm.com/coligo/cli/blob/main/script/publish.to.repo.sh"""
289+
"""Starts up a Jenkins build.
290+
Copied some of the logic from https://github.ibm.com/coligo/cli/blob/main/script/publish.to.repo.sh so this might not be the best solution.
291+
292+
This CURL command works (missing all the OS options but you get the idea). We should be using 'buildWithParameters' I think, but I couldn't get it to work.
293+
curl -X POST https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Publish%20Plugin%20to%20YS1/build \
294+
--user $JENKINS_USER:$JENKINS_TOKEN \
295+
--form json='{"parameter": [{"name":"Plugin_Name", "value":"sl"},'\
296+
'{"name":"Version", "value": "1.4.2"},'\
297+
'{"name":"Description", "value": "Manage Classic infrastructure services"},'\
298+
'{"name":"min_cli_version", "value": "2.18.0"},'\
299+
'{"name":"private_endpoint_supported", "value": true},'\
300+
'{"name":"Checksum_Linux_X86", "value":"d069b943532f69feadd292d6d1c62eece8ca1112"},'\
301+
'{"name":"Url_Linux_X86", "value":"https://s3.us-east.cloud-object-storage.appdomain.cloud/softlayer-cli-binaries/sl-1.4.2-linux-386"}]}' -v
302+
"""
290303
checksums = self.getChecksums()
291-
jenkinsUrl = 'https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Publish%20Plugin%20to%20YS1/build'
304+
jenkinsUrl = 'https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Publish%20Plugin%20to%20YS1'
292305
jenkins_token = os.getenv('JENKINS_TOKEN')
293306
if not jenkins_token:
294307
raise Exception("JENKINS_TOKEN is not set to an API key")
295308
auth = f"cgallo@us.ibm.com:{jenkins_token}"
296309
form_json = {
297-
"parameters": [
310+
"parameter": [
298311
{"name": "Plugin_Name", "value":"sl"},
299312
{"name": "Version", "value":self.version},
300313
{"name": "Description", "value":"Manage Classic infrastructure services"},
@@ -306,12 +319,17 @@ def runJenkins(self):
306319
for x in checksums.keys():
307320
urlData = {'name': f"Url_{x}", "value": self.cnd_url + checksums[x]['file']}
308321
checkData = {'name': f"Checksum_{x}", "value": checksums[x]['checksum']}
309-
form_json['parameters'].append(urlData)
310-
form_json['parameters'].append(checkData)
322+
form_json['parameter'].append(urlData)
323+
form_json['parameter'].append(checkData)
311324

312325
print(f"[yellow]Trying to start jenkins job on {jenkinsUrl}")
313-
result = requests.post(jenkinsUrl, auth=('cgallo@us.ibm.com', jenkins_token), data=form_json)
314-
print(result)
326+
print(form_json)
327+
result = requests.post(f"{jenkinsUrl}/build", auth=('cgallo@us.ibm.com', jenkins_token), data={'json':json.dumps(form_json)})
328+
if (reult.status_code == 201 ):
329+
print(f"[green] Created Job! Check {jenkinsUrl}" )
330+
else:
331+
print(f"[red]Error: {result.status_code} {result.reason}")
332+
raise Excetion("Error in runJenkins()")
315333

316334

317335

@@ -394,9 +412,10 @@ def i18n(ctx):
394412
genBinData()
395413

396414
if __name__ == '__main__':
397-
try:
398-
cli()
399-
except Exception as e:
400-
print(f"[red]{e}")
415+
cli()
416+
# try:
417+
# cli()
418+
# except Exception as e:
419+
# print(f"[red]{e}")
401420

402421

plugin/resources/i18n_resources.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)