Pipeline Script - Robot Framework
pipeline {
agent any
environment {
//ROBOT_OPTIONS = "--variable SELENIUM_REMOTE_URL:http://192.168.1.3:4444/wd/hub"
SELENIUM_HUB_URL = "http://192.168.1.5:4444/wd/hub"
GIT_USER = 'createand'
GIT_EMAIL = 'createand@gmail.com'
GIT_REPO = 'git@github.com:createand/robot-report.git'
GIT_TOKEN = credentials('git-pull-token')
GIT_PUSH = 'github-pat'
GIT_PASS = 'password'
//DEN_CRE = credentails('den-pat')
}
stages {
stage('Checkout') {
steps {
git(
branch: 'main',
url: 'https://github.com/createand/selenium-robot-test.git',
credentialsId: 'github-pat'
)
}
}
stage('Setup Python') {
steps {
script {
// pip kurulu mu kontrol et, değilse kur
try {
sh 'python3 --version'
sh 'pip3 --version'
} catch (Exception e) {
echo "Python/pip not found, installing..."
sh '''
apt-get update
apt-get install -y python3 python3-pip
python3 -m pip install --upgrade pip --break-system-packages
'''
}
}
}
}
stage('Install dependencies') {
steps {
sh 'rm -rf venv'
sh 'apt install python3.11-venv -y'
sh 'python3 -m venv venv'
sh '. venv/bin/activate'
sh 'venv/bin/pip install pabot'
sh 'venv/bin/pip install -r requirements.txt'
}
}
stage('Run Tests') {
steps {
sh '. venv/bin/activate'
// catchError sayesinde test fail olsa da pipeline fail olmaz
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
sh 'venv/bin/robot --variablefile ./configs/variable_jenkins.py --outputdir results --output output.xml --report report.html --log log.html tests/'
}
}
}
stage('Publish Report') {
steps {
// Robot Framework plugin kullanıyor
robot outputPath: 'results'
}
}
stage('Publish HTML Report') { //Publish HTML Reports kurulu olmalı
steps {
publishHTML(target: [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'results',
reportFiles: 'report.html,log.html',
reportName: 'Robot Framework Report'
])
}
}
stage('Send Report Git'){
steps {
withCredentials([usernamePassword(credentialsId: 'git-pull-token', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
sh 'git config --global user.name "${GIT_USER}"'
sh 'git config --global user.email "${GIT_EMAIL}"'
sh 'mkdir -p /var/jenkins_home/workspace/DockerSeleniumTest/tmp_results'
sh 'cd /var/jenkins_home/workspace/DockerSeleniumTest/tmp_results'
//sh 'git submodule https://${GIT_USER}:${GIT_TOKEN}@github.com/createand/robot-report.git tmp_results'
sh 'rm -rf .git'
sh 'cp -r $WORKSPACE/../index.html /var/jenkins_home/workspace/DockerSeleniumTest/tmp_results'
sh 'cp -r $WORKSPACE/results/*.* /var/jenkins_home/workspace/DockerSeleniumTest/tmp_results'
sh 'git init'
sh 'git remote add origin https://${GIT_TOKEN}@github.com/createand/robot-report.git || true'
//sh 'git remote add origin ${GIT_REPO} || true'
sh 'git add .'
sh 'git commit -m "Build $BUILD_NUMBER reports" || true'
sh 'git branch -M main'
// sh 'git pull -f https://${GIT_TOKEN}@github.com/createand/robot-report.git main'
sh 'git subtree split --prefix=tmp_results -b tmp_branch'
sh 'git push -f https://${GIT_TOKEN}@github.com/createand/robot-report.git tmp_branch:main'
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'results/*', fingerprint: true
//junit 'results/output.xml'
robot outputPath: 'results',
outputFileName: 'output.xml',
reportFileName: 'report.html',
logFileName: 'log.html'
}
}
}
Pipeline Script - Tomcat
pipeline {
agent any
tools {
maven "test-maven" // Jenkins'te Maven tanımlıysa kullan
}
environment {
TOMCAT_URL = 'http://192.168.1.3:9000'
DEPLOY_CRED = credentials('tomcat-cred') // Jenkins credentials ID
}
stages {
stage('Checkout') {
steps {
git branch: 'main',
url: 'https://github.com/createand/jaxbmevzuat.git'
}
}
stage('Build') {
steps {
sh 'mvn clean package -DskipTests'
}
}
/*stage('Deploy to Tomcat') {
steps {
deploy adapters: [
tomcat9(
credentialsId: "tomcat-cred",
path: '/jaxbmevzuat',
url: "${TOMCAT_URL}"
)
],
contextPath: '/jaxbmevzuat',
war: 'target/jaxbmevzuat.war'
}
}*/
stage('Deploy to Tomcat') {
steps {
withCredentials([usernamePassword(
credentialsId: 'tomcat-cred',
usernameVariable: 'TOMCAT_USER',
passwordVariable: 'TOMCAT_PASS'
)]) {
sh """
curl -s -o /dev/null -w "%{http_code}" \\
-u $TOMCAT_USER:$TOMCAT_PASS \\
--upload-file target/jaxbmevzuat.war \\
"$TOMCAT_URL/manager/text/deploy?path=/jaxbmevzuat&update=true"
"""
}
}
}
}
}
Pipeline Script - Playwright
pipeline {
agent any
tools {
nodejs 'NodeJS' // Jenkins de tanımlı olan yazılacak
}
stages {
stage('Checkout') {
steps {
git url: 'https://github.com/createand/basic-playwright.git', branch: 'main'
}
}
stage('Install Dependencies') {
steps {
sh 'npm install'
sh 'npx playwright install-deps'
sh 'npx playwright install'
}
}
stage('Run Tests') {
steps {
sh 'npx playwright test --reporter=html'
}
}
}
post {
always {
// HTML raporunu Jenkins'e arşivle
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'playwright-report',
reportFiles: 'index.html',
reportName: 'Playwright Test Raporu'
])
archiveArtifacts artifacts: 'playwright-report/**', allowEmptyArchive: true
}
}
}