0

I would like to have a environment variable COMPOSE_PROJECT_NAME with the value denpal-4 for a Jenkins job with build_id 4.

environment { COMPOSE_PROJECT_NAME = 'denpal-$(BUILD_ID)' } 

The alternative would be writing this in every sh-block

sh ''' export COMPOSE_PROJECT_NAME = 'denpal-$(BUILD_ID)' code... ''' 

This would go against the DRY (Don't repeat yourself) principle however. Is something in environment {} possible?

UPDATE/ANSWER: double quotes instead of single quotes fixed it.

1 Answer 1

2

Yes, you can assign the value to variable in environment stage (using env as a prefix to the variable) and then can use it in any stage, please see below:-

environment { env.COMPOSE_PROJECT_NAME = "denpal-${BUILD_ID}" } 
Sign up to request clarification or add additional context in comments.

2 Comments

WorkflowScript: 12: Expected string literal @ line 12, column 5. env.COMPOSE_PROJECT_NAME = 'denpal-${BUILD_ID}'
Double quotes fixed it!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.