How to Create a Common Function to Execute a Python Script in Jenkins

Return a list of values from Python Script to Jenkins Pipeline

Since you're using the Pipeline DSL, you can use Groovy to process the result of the call to bat

pipeline {
agent any
steps {
step('Get Build Numbers') {
script {
def version_numbers = bat(script: 'python get_version_numbers.py', returnStdout: true)
def versions_as_array = version_numbers.split('\n')
}
}
}
}

From there, it's a matter of generating the build steps and wrapping them in a parallel block. For that, take a look at this answer: Ideas to implement dynamic parallel build using jenkins pipeline plugin

Get the ouput result for a python script in a Jenkinsfile pipeline groovy

stage('Deployment on FTP') {
steps {
script {
env.WAR_NAME = sh(script: "python scripts-ci/scripts/build/front/scripts/lib/war_name.py ${customerProfileId} ${FORCE_CUSTOMER_NAME}", returnStdout: true).toString().trim()
}
}
}

Here is the code of my current Jenkinsfile working (scripts-ci beeing the folder when I've clone my python scripts needed.

        stage("Git checkout") {
steps {
dir("scripts-ci") {
git branch: "${GIT_BRANCH_CI}",
credentialsId: "${GIT_CREDENTIALS_ID}",
url: "${GIT_URL_CI}"
}
}
}


Related Topics



Leave a reply



Submit