Setting Access token
with direnv
and using it is a common practice of AWS CLI
.
Also, having the environment variable hold the User credential is a rather good way.
There are many Credentials such as username
, password
, access token
, ....
This is a story when you want to use this at the deployment destination.
It is written in Don Pisha in Jenkins User Handbook.
You can now refer to it in pipeline
-stage
-steps
.
Another method is described in this section. You can give Jenkins Credential information, right? (It is a guy who operates with GUI) You can refer to that.
Usernames and passwords - Using a Jenkinsfile
It's just a little tricky, so I'll explain it.
hoge_credential
Jenkinsfile
.USER_CREDENTIAL_USR
USER_CREDENTIAL_PSW
Sample of Jenkinsfile
Jenkinsfile
pipeline {
environment {
USER_CREDENTIAL = credentials('$hoge_credential')
}
}
It will be like this.
Since it can be referenced in Jenkinsfile
, it can also be referenced as ENV
from Capistrano
.
If you write with USER_CREDENTIAL
earlier,
deploy.rb
namespace :deploy do
tasks :sample-task do
on roles(:app) do
with hoge_user: ENV['USER_CREDENTIAL_USR'] do
with hoge_passwd: ENV['USER_CREDENTIAL_PSW'] do
capture(:echo, '--user=$HOGE_USER', '--password=$HOGE_PASSWD')
end
end
end
end
end
It will be.
Recommended Posts