From 5eb7303247970f9acbdf21fc6cd1399a807a0505 Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:06:29 -0800 Subject: [PATCH] let's give this a shot? --- Jenkinsfile | 14 +++++++++++--- publish_package.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 publish_package.py diff --git a/Jenkinsfile b/Jenkinsfile index 05da1a9..56082cc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,9 +21,17 @@ node ('windows') { bat """pyinstaller --noconfirm --onefile --windowed "./main.py" """ } - // Wrap Up - Archive the Generated Executables, Tear Down the Build System. - stage('Archive/Teardown') { - archiveArtifacts artifacts: "dist\\*.exe" + // Wrap Up - Archive the Generated Executables + stage('Archive') { + // Provide Credentials to Upload to Gitea + withCredentials([ + usernamePassword(credentialsId: 'gitea-jenkinsbot', + usernameVariable: 'GITEA_USER', + passwordVariable: 'GITEA_PASS') + ]) { + // Publish the Latest + bat "python publish_package.py" + } } } \ No newline at end of file diff --git a/publish_package.py b/publish_package.py new file mode 100644 index 0000000..b8038d7 --- /dev/null +++ b/publish_package.py @@ -0,0 +1,39 @@ +################################################################################ +""" +Publish the EXE as a package to Gitea. +""" +################################################################################ + +import os +import requests + +OWNER = "jenkinsbot" +PKG_NAME = "ComputerKeeper-BUILD" +PKG_VERSION = "latest" +FILE_NAME = "main.exe" + +AUTH_USER = os.getenv("GITEA_USER") +AUTH_PASS = os.getenv("GITEA_PASS") + +HOST = "https://gitea.stanleysolutionsnw.com" + +def main(): + """Attempt Deleting the Package, then Add the New Package with File.""" + s = requests.Session() + s.auth = (AUTH_USER, AUTH_PASS) + # Delete Package + try: + s.delete( + f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}" + ) + except Exception: + # Intentionally Overlook Issues Here + pass + # Add New Package + s.put( + ( + f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}/" + + FILE_NAME + ), + data=open(f"dist/{FILE_NAME}", 'rb').read(), + )