From 11d7334157bcb4e7acde862dc6861d9562b295ce Mon Sep 17 00:00:00 2001 From: Guillem Hernandez Sola Date: Tue, 30 Jun 2026 15:52:24 +0200 Subject: [PATCH] NEw PLaywright --- jenkins/FCBMasiaTw | 106 +++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/jenkins/FCBMasiaTw b/jenkins/FCBMasiaTw index 403d2fd..aaad55d 100644 --- a/jenkins/FCBMasiaTw +++ b/jenkins/FCBMasiaTw @@ -16,7 +16,6 @@ pipeline { stage('Checkout Code') { steps { - // Pulls the code from the repository where this Jenkinsfile lives checkout scm } } @@ -24,59 +23,84 @@ pipeline { stage('Setup Python & Install Dependencies') { steps { sh ''' - set -e # Exit immediately if a command exits with a non-zero status - - # Create a virtual environment named 'venv' - python3 -m venv venv - - # Activate the virtual environment and install dependencies - . venv/bin/activate && \ - pip install --upgrade pip && \ - pip install -U atproto tweety-ns playwright httpx arrow python-dotenv moviepy grapheme - - # Check if moviepy is installed - pip list | grep moviepy || { echo 'MoviePy installation failed!'; exit 1; } - - # Check if FFmpeg is installed - ffmpeg -version || { echo 'FFmpeg is not installed!'; exit 1; } + set -e + cd "$WORKSPACE" - # Verify that moviepy can be imported - python3 -c "import moviepy" || { echo 'MoviePy import failed!'; exit 1; } + # Crea el venv + python3 -m venv venv - # Install the local browser binaries for this environment - playwright install chromium + # Usa python3 -m pip per evitar problemes de shebang amb sh/dash + "$WORKSPACE/venv/bin/python3" -m pip install --upgrade pip wheel setuptools + + "$WORKSPACE/venv/bin/python3" -m pip install -U \ + atproto \ + tweety-ns \ + playwright \ + httpx \ + arrow \ + python-dotenv \ + moviepy \ + grapheme + + # Verificació moviepy + "$WORKSPACE/venv/bin/python3" -m pip list | grep moviepy \ + || { echo 'MoviePy installation failed!'; exit 1; } + + # Verificació FFmpeg + ffmpeg -version \ + || { echo 'FFmpeg is not installed!'; exit 1; } + + # Verificació imports + "$WORKSPACE/venv/bin/python3" -c "import moviepy; print('moviepy OK')" + "$WORKSPACE/venv/bin/python3" -c "import atproto; print('atproto OK')" + "$WORKSPACE/venv/bin/python3" -c "import playwright; print('playwright OK')" + + # Instal·lació binaris Playwright + PLAYWRIGHT_BROWSERS_PATH=/var/jenkins_home/.playwright-browsers \ + "$WORKSPACE/venv/bin/python3" -m playwright install chromium ''' } } stage('Run Script') { steps { - // Securely inject Jenkins credentials as environment variables withCredentials([ - string(credentialsId: 'TWITTER_USERNAME', variable: 'TWITTER_USERNAME'), - string(credentialsId: 'TWITTER_PASSWORD', variable: 'TWITTER_PASSWORD'), - string(credentialsId: 'TWITTER_FCB_EMAIL', variable: 'TWITTER_FCB_EMAIL'), - string(credentialsId: 'TWITTER_FCBMASIA_HANDLE', variable: 'TWITTER_FCBMASIA_HANDLE'), - string(credentialsId: 'BSKY_MQUB_HANDLE', variable: 'BSKY_MQUB_HANDLE'), - string(credentialsId: 'BSKY_MQUB_PASSWORD', variable: 'BSKY_MQUB_PASSWORD') + string(credentialsId: 'TWITTER_USERNAME', variable: 'TWITTER_USERNAME'), + string(credentialsId: 'TWITTER_PASSWORD', variable: 'TWITTER_PASSWORD'), + string(credentialsId: 'TWITTER_FCB_EMAIL', variable: 'TWITTER_FCB_EMAIL'), + string(credentialsId: 'TWITTER_FCBMASIA_HANDLE', variable: 'TWITTER_FCBMASIA_HANDLE'), + string(credentialsId: 'BSKY_MQUB_HANDLE', variable: 'BSKY_MQUB_HANDLE'), + string(credentialsId: 'BSKY_MQUB_PASSWORD', variable: 'BSKY_MQUB_PASSWORD') ]) { sh ''' - # Activate the exact same virtual environment so Python finds Playwright and Arrow - . venv/bin/activate - - # Run the daemon with the injected credentials - python3 twitter2bsky.py \ - --twitter-username "$TWITTER_USERNAME" \ - --twitter-password "$TWITTER_PASSWORD" \ - --twitter-email "$TWITTER_FCB_EMAIL" \ - --twitter-handle "$TWITTER_FCBMASIA_HANDLE" \ - --bsky-handle "$BSKY_MQUB_HANDLE" \ - --bsky-password "$BSKY_MQUB_PASSWORD" \ - --bsky-base-url https://eurosky.social \ - --bsky-langs ca + set -e + cd "$WORKSPACE" + + PLAYWRIGHT_BROWSERS_PATH=/var/jenkins_home/.playwright-browsers \ + "$WORKSPACE/venv/bin/python3" twitter2bsky.py \ + --twitter-username "$TWITTER_USERNAME" \ + --twitter-password "$TWITTER_PASSWORD" \ + --twitter-email "$TWITTER_FCB_EMAIL" \ + --twitter-handle "$TWITTER_FCBMASIA_HANDLE" \ + --bsky-handle "$BSKY_MQUB_HANDLE" \ + --bsky-password "$BSKY_MQUB_PASSWORD" \ + --bsky-base-url https://eurosky.social \ + --bsky-langs ca ''' } } } } -} + + post { + always { + archiveArtifacts( + artifacts: '*.log, *.json, screenshot_*.png', + allowEmptyArchive: true + ) + } + success { echo '✅ Sync cycle completed successfully.' } + failure { echo '❌ Sync cycle failed — check archived logs and screenshots.' } + unstable { echo '⚠️ Sync cycle finished with warnings.' } + } +} \ No newline at end of file