Fetching secret file with Jenkins declarative syntax

Viewed 1666

Is there a syntax in a declarative Pipeline to fetch secret file in environment {} section ?

I am aware of the following syntax, but I'm not sure it's the recommended way for a declarative Pipeline.

  withCredentials( [file(credentialsId: 'my-secret-file', variable: 'MY_SECRET_FILE')])
    {
        sh """
            ln -s ${env.MY_SECRET_FILE} download/mysecretfile.crt
        """
    }

Thanks.

1 Answers
environment {
  PATH_TO_SECRET_FILE = credentials('secret-file')  
}
Related