How can I use Jenkins Sidebar Link Plugin in pipeline step?

To find out how to do something in Declarative Pipeline, you can use the Directive Generator at http://JENKINS_URL/directive-generator/. This provides a user interface similar to the Job Configuration. However upon selecting "options" -> "Add" -> "sidebarLinks" -> fill in fields -> "Generate", nothing will be generated due to an internal server error.

The following Declarative Pipeline syntax works for a single job:

pipeline {
    agent any
    
    options {
        sidebarLinks([
            [displayName: 'Side Bar Example', iconFileName: '', urlName: 'http://example.com']
        ])
    }

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }
}

However, you mentioned that you want to reuse these links in different jobs through use of a Shared Pipeline Library. Unfortunately, Shared Pipeline Libraries can not modify the options section of a Declarative Pipeline, with the exception of generating your entire pipeline { } in a single def call().

Fortunately, Scripted Pipeline can override that part of a configuration. Using the Snippet Generator at http://JENKINS_URL/pipeline-syntax/, you can generate the following bit of code that you can put in a Shared Pipeline Library, e.g. in var/mySidebar.groovy:

def call() {
    properties([
        sidebarLinks([[
            displayName: 'My fancy sidebar url', iconFileName: '', urlName: 'https://example.com'
        ]])
    ])
}

You can then use that in either a scripted pipeline:

library('my-sidebar')

mySidebar()

node() {
    stage('Hello') {
        sh 'echo "Hello World!"'
    }
}

Or a script block of a Declarative Pipeline:

library('my-sidebar')

script {
    mySidebarScripted()
}

pipeline {
    agent any
    
    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }
}