convert declarative pipeline to scripted pipeline

I already used the following declarative script as a part of my cleanup script, now I should convert it to the scripted pipeline, how I can convert the post to the scripted pipeline?

stages {
stage ('Cleanup Feature Releases') {
    agent any
    steps {
        script {
            envParameters = Utils.getEnvParameters("${TARGET_ENV}")
            withKubeConfig([credentialsId: envParameters.K8S_TOKEN,
                            serverUrl: envParameters.K8S_API_SERVER,
                            contextName: CONTEXT_NAME
            ]) {
                sh "Running on ${params.OVERRIDE_NAMESPACE}"
            }
        }
    }
    post {
        failure {
            cleanUpNotification("FAILURE", params.DRY_RUN)
        }
        aborted {
            cleanUpNotification("ABORTED", params.DRY_RUN)
        }
        success {
            cleanUpNotification("SUCCESS", params.DRY_RUN)
        }
    }
}

}

Go to Source
Author: Mkash

How to run Dockerfile agent on a Jenkins Slave Node?

I have an issue with Running Dockerfile in Jenkins Pipeline on a Slave Node server.
Have posted in main StackOverflow portal. happy to see this DevOps Stackexachange portal.

just linking the ticket here : https://stackoverflow.com/questions/63364558/how-to-run-dockerfile-agent-on-a-jenkins-slave-node/63366121

It would be really helpful if someone can share their thoughts.
Thanks in advance.

Go to Source
Author: Venkatesha K

Deploy .NET application from Jenkins on Linux to MS Azure Web service

We have .NET application which deployed to Azure Web services. Now is time to create deployment pipeline for it.

And want to know what is high level plan how .NET application can be deployed to Azure from Linux servers based on CentOS.

Do we need an AZ cli installed on Linux server to deploy it and Azure .NET SDK?

Go to Source
Author: pleyades

Unable to get value of password parameter into another parameter

In Jenkins pipeline parameter say Branches of type Active Choice Reactive Parameter, I’ve to auto-populate branch names hence I’ve following command, which I can execute in parameter’s Groovy script –

svn ls <url> --non-interactive --no-auth-cache --trust-server-cert --username <username>--password <password>

username can be retrieved using User.current().getId()

I’ve Password parameter of Password Parameter type. To use value of this parameter in Groovy script of Branches, I’ve added Password parameter in Referenced parameters of Branches

But I cannot see its value reflected in Branches parameter. Can you please suggest how this can be handled?

Or any other way to pass Password value or authentication details so I can execute svn command.

Go to Source
Author: TDHM

How to get logged in username of Jenkins in parameter’s Groovy script?

In Jenkins parameter, I’m writing Groovy script and in that script I need to pass Jenkins logged in username NOT user. User and username, could be different

Ex – User, that is displayed left to ‘log out’, could be – Bob Gill and username, used to login – could be – bob

User can be retrieved using User.current(). Please tell me how to get username.

NOTE I don’t need username in pipeline code. I need it in Groovy script of parameter.

Go to Source
Author: TDHM

simulate post step for dynamically generated Jenkins pipeline stages

The following simplified Jenkinsfile dynamically generates sequentially executed stages; however, I cannot create a post step for these dynamically stages, like so:

pipeline {
    agent none
    stages {
        stage('Gen Stages') {
            steps {
                script {
                    def stageNames = ["st1", "st2", "st3"]
                    stageNames.each { stageName ->
                        createStage(stageName)
                    }
                }
            }
        }
    }
    post {
        always {
            echo "post > always"
        }
        success {
            echo "post > success"
        }
    }
}

def createStage(String stageName) {
    stage(stageName) {
        echo "Stage: ${stageName}"
    }
    // I want to uncomment and use code below - or something effectively simiarl:
    // post {
    //     always {
    //         echo "${stageName} > post > always"
    //     }
    //     success {
    //         echo "${stageName} > success > always"
    //     }
    // }
}

I would like to be able to use the commented-out post {} stage, or something effectively similar.

If at all possible, I’d like to use the DSL as much as possible and avoid scripted pipelines.

Suggestions?

Go to Source
Author: Trevor

Jenkins Plugin:Extended Choice Parameter from JSON file

Jenkins Plugin:Extended Choice Parameter from JSON file

Extended Choice Parameter plugin query: How to load params dynamically from a JSON file for jenkins build job. Here is my jenkins script to add normal parameters and Extended Choice parameters as well.

p

roperties([
        [$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '500']],
        parameters([extendedChoice( 
        defaultValue: 'One,Two,Three,Four', 
        description: '', 
        multiSelectDelimiter: ',', 
        name: 'SAMPLE_EXTENDED_CHOICE', 
        quoteValue: false, 
        saveJSONParameterToFile: false, 
        type: 'PT_CHECKBOX', 
        value:'One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten', 
        visibleItemCount: 10)
        ])
])

This is working. But I want to be able to load parameters from a JSON file (using Extended Choice Parameter plugin). How can I modify the above script to accomplish that? PS: Here is the reference for Extended Parameter plugin. https://plugins.jenkins.io/extended-choice-parameter/

Go to Source
Author: Vineel