Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verify tls flag #1

Merged
merged 9 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create exec file with Pyinstaller
run: |
pip install pyinstaller
pyinstaller --clean --onefile jenkins.py
tar -cvf release.tar.gz dist/
- uses: ncipollo/release-action@v1
with:
artifacts: "release.tar.gz"
generateReleaseNotes: true
#bodyFile: "body.md"
22 changes: 22 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Python test

on: [push]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with Ruff
run: |
pip install ruff
ruff check --output-format=github .
continue-on-error: true
23 changes: 13 additions & 10 deletions jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
This script only support user TOKEN as the password and not the actual user password
"""
import requests
import re
import sys
import json
import time
import os
import argparse
import logging

QUEUE_POLL_INTERVAL = 2
JOB_POLL_INTERVAL = 20
JOB_POLL_INTERVAL = 10
OVERALL_TIMEOUT = 3600 # 1 hour


Expand All @@ -34,6 +31,11 @@ def main(arguments):
'--jenkins_url',
help="Jenkins full URL. example : http://localhost:8080",
type=str)
parser.add_argument(
'--tls-verify',
default = True,
help="Enable or disable TLS verification for HTTPS connections",
type=bool)
parser.add_argument(
'-p',
'--param',
Expand Down Expand Up @@ -61,7 +63,7 @@ def main(arguments):
else:
start_build_url = '{}/job/{}/build'.format(args.jenkins_url, job_name)

r = requests.post(start_build_url, auth=auth)
r = requests.post(start_build_url, auth=auth, verify=args.tls_verify)

if r.status_code // 200 == 1:
logging.info('Job "{}" was launched successfully'.format(job_name))
Expand All @@ -77,13 +79,14 @@ def main(arguments):
logging.info('{} Job {} added to queue: {}'.format(time.ctime(), job_name,
job_info_url))
while True:
l = requests.get(job_info_url, auth=auth)
jqe = l.json()
job_info_request = requests.get(job_info_url, auth=auth, verify=args.tls_verify)
jqe = job_info_request.json()
task = jqe['task']['name']
try:
job_id = jqe['executable']['number']
logging.info("job have been launched with the id: {}".format(job_id))
break
except:
except Exception:
logging.info("no job ID yet for build: {}".format(task))
time.sleep(QUEUE_POLL_INTERVAL)
elasped_time += QUEUE_POLL_INTERVAL
Expand All @@ -99,7 +102,7 @@ def main(arguments):
start_epoch = int(time.time())
while True:
logging.info("{}: Job started URL: {}".format(time.ctime(), job_url))
j = requests.get(job_url, auth=auth)
j = requests.get(job_url, auth=auth, verify=args.tls_verify)
jje = j.json()
result = jje['result']
if result == 'SUCCESS':
Expand All @@ -124,7 +127,7 @@ def main(arguments):

cur_epoch = int(time.time())
if (cur_epoch - start_epoch) > OVERALL_TIMEOUT:
logging.info("{}: No status before timeout of {} secs".format(
logging.info("No status before timeout of {} secs".format(
OVERALL_TIMEOUT))
sys.exit(1)

Expand Down
Loading