# Credentials Error

**URL:** <https://community.jenkins.io/t/credentials-error/6974>\
**Category:** Ask a question\
**Tags:** question, pipeline\
**Created:** [April 21, 2023, 4:36pm UTC](https://community.jenkins.io/t/credentials-error/6974 "2023-04-21T16:36:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![autocicd](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@autocicd](https://community.jenkins.io/u/autocicd)\
**Post date:** [April 21, 2023, 4:36pm UTC](https://community.jenkins.io/t/credentials-error/6974/1 "2023-04-21T16:36:02Z")

</div>

Getting the following error when trying to bring my credentials into Jenkinsfile:

Wondering what the fix for this is?

WorkflowScript: 8: Environment variable values must either be single quoted, double quoted, or function calls. @ line 8, column 23.  
DOCKER\_USERNAME = credentials(‘Jenkey’).username  
^

WorkflowScript: 9: Environment variable values must either be single quoted, double quoted, or function calls. @ line 9, column 23.  
DOCKER\_PASSWORD = credentials(‘Jenkey’).password

pipeline {  
agent any

environment {  
DOCKER\_REGISTRY = “[docker.io](http://docker.io)”  
DOCKER\_IMAGE = “10088989/my-node-app”  
DOCKER\_TAG = “latest”  
DOCKER\_USERNAME = credentials(‘Jenkey’).username  
DOCKER\_PASSWORD = credentials(‘Jenkey’).password  
}

stages {  
stage(‘Build’) {  
steps {  
withCredentials([usernamePassword(credentialsId: ‘Jenkey’, usernameVariable: ‘DOCKER\_USERNAME’, passwordVariable: ‘DOCKER\_PASSWORD’)]) {  
sh “docker login -u $DOCKER\_USERNAME -p $DOCKER\_PASSWORD $DOCKER\_REGISTRY”  
sh “docker build -t $DOCKER\_REGISTRY/$DOCKER\_IMAGE:$DOCKER\_TAG .”  
^

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [April 21, 2023, 5:12pm UTC](https://community.jenkins.io/t/credentials-error/6974/2 "2023-04-21T17:12:25Z")

</div>

Maybe not the correct single quote character?  
Can you edit your post and make the pipeline snippet formatted as `code`  
Does it look like this?  
`DOCKER_USERNAME = credentials('Jenkey').username`

Why you set environment variables with docker credentials and then also use the withCredentials step setting the same variables again?  
I would probably only use the withCredentials as this limits the lifetime of the variables to this step only while the global env variables have the complete pipeline execution as lifetime.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [April 22, 2023, 6:12am UTC](https://community.jenkins.io/t/credentials-error/6974/3 "2023-04-22T06:12:46Z")

</div>

> [@autocicd](#):
>
> DOCKER\_PASSWORD = credentials(‘Jenkey’).password

doesn’t feel right.

`DOCKER = credentials('Jenkey')`  
is the right way i think, then you end up with  
$DOCKER\_USR and $DOCKER\_PWD or something

`DOCKER_PASSWORD = "${credentials('Jenkey').password}"`

might also work, because as it says its expecting a quoted string, or I think credentials() is a special case
