I have a Jenkinsfile like this
pipeline {
agent { label 'master' }
stages {
stage('1') {
steps {
script {
sh '''#!/bin/bash
source $EXPORT_PATH_SCRIPT
cd $SCRIPT_PATH
python -m scripts.test.test
'''
}
}
}
stage('2') {
steps {
script {
sh '''#!/bin/bash
source $EXPORT_PATH_SCRIPT
cd $SCRIPT_PATH
python -m scripts.test.test
'''
}
}
}
}
}
As you can see, In both stages I am using the same script and calling the same file. Can I move this step to a function in Jenkinsfile and call that function in script? like this
def execute script() {
return {
sh '''#!/bin/bash
source $EXPORT_PATH_SCRIPT
cd $SCRIPT_PATH
python -m scripts.test.test
'''
}
}