Home > Net >  No such DSL method 'openShiftInstall' found among steps
No such DSL method 'openShiftInstall' found among steps

Time:07-26

I'm trying to call the following funtion in Jenkins:

def openShiftInstall(char CLUSTER_URL, char TOKEN) {
    sh '''
        oc login --token='''TOKEN''' --server='''CLUSTER_URL'''
        
        if helm history --max 1 $ARTIFACT_ID 2>/dev/null | grep FAILED | cut -f1 | grep -q 1; then
           helm delete --purge $ARTIFACT_ID
        fi
        
        helm upgrade --install -f container-root/helm/values-devref.yaml --set image.version=$RELEASE_VERSION $ARTIFACT_ID container-root/helm --namespace ${NAMESPACE} --debug
    '''
}

in this stage

 environment {
                                    NAMESPACE = 'test'

                                    OC_a_DEV_TOKEN = 123
                                    OC_b_DEV_TOKEN = 456
                                    OC_a_DEV_CLUSTER_URL = 'https://api.ocp4-a.net:443'
                                    OC_b_DEV_CLUSTER_URL = 'https://api.ocp4-b.net:443'

                                }
                                steps {
                                    container('oc') {
                                        script {
                                            openShift.openShiftInstall("${OC_a_DEV_CLUSTER_URL}", "${OC_a_DEV_TOKEN}")
                                            //openShift.openShiftInstall(${OC_b_DEV_CLUSTER_URL}, ${OC_b_DEV_TOKEN})
                                        }
                                    }
                                }

I'm getting this error:

java.lang.NoSuchMethodError: No such DSL method 'openShiftInstall' found among steps

Somebody can help me to understand what I'm doing here wrong?

Maybe is there a better solution to loop through multiple cluster installation with different parameters? Right now I'm just trying to run the same function twice, but even one is not working with the parameters.

CodePudding user response:

You seems to be accepting a Char in the function openShiftInstall but you are passing a String. Change the method signature like below.

def openShiftInstall(def CLUSTER_URL, def TOKEN) {
    sh '''
        oc login --token='''TOKEN''' --server='''CLUSTER_URL'''
        
        if helm history --max 1 $ARTIFACT_ID 2>/dev/null | grep FAILED | cut -f1 | grep -q 1; then
           helm delete --purge $ARTIFACT_ID
        fi
        
        helm upgrade --install -f container-root/helm/values-devref.yaml --set image.version=$RELEASE_VERSION $ARTIFACT_ID container-root/helm --namespace ${NAMESPACE} --debug
    '''
}

CodePudding user response:

I changed to the following and it seems to working now.

def openShiftInstall(String CLUSTER_URL, String TOKEN) {
    unstash 'lapc-docker-root'
    sh '''
        oc login --token='''   TOKEN   ''' --server='''   CLUSTER_URL   '''
        
        if helm history --max 1 $ARTIFACT_ID 2>/dev/null | grep FAILED | cut -f1 | grep -q 1; then
           helm delete --purge $ARTIFACT_ID
        fi
        
        helm upgrade --install -f container-root/helm/values-devref.yaml --set image.version=$RELEASE_VERSION $ARTIFACT_ID container-root/helm --namespace ${NAMESPACE} --debug
    '''
}
  • Related