I believe I have found the solution.
Summary
- Do not use Specified by permalink
- Use Specific build and set build number to
${PROMOTED_NUMBER}
The Solution
Prerequisites
- The Copy Artifact Plugin must be installed.
- Archive the artifacts you want the promotions to access
- In Post-build Actions add the action Archive the artifacts and set Files to archive to what ever you want your promotion to access.
- Do not discard old artifacts
- In the Job Configuration, deselect Discard Old Builds or ensure that its settings will keep the artifacts for as long as you want to promote your builds.
Promotion setup:
Setup up your promoted build with name and criteria as usual.
In the Actions section add the action Copy artifacts from an other project, and set these values.
- Project Name:
${PROMOTED_JOB_NAME}
- Which Build: Specific Build
- Build Number:
${PROMOTED_NUMBER}
- Artifacts to Copy:
path/to/your/artifacts/**
- Target:
${BUILD_TAG}
Then add the actions you really want to do. For example add the action Archive the artifacts to save the artifacts. Remember to prefix your paths with ${BUILD_TAG}
e.g. ${BUILD_TAG}/path/to/your/artifacts/**
Notes on why
Copying artifacts
As you probably know by now, the promotion should not expect to have access the the content of the workspace of the build. It might be executed on a different server, and it might have access to no workspace at all or the workspace from an older or newer build. It is therefore required to copy the artifacts you want to use to the current workspace.
This is also the reason why the Target value is set. The workspace might be poluted with other builds or promototions. Setting target to ${BUILD_TAG}
Prevents any conflicts with files already in the workspace, by creating a folder unique to the promotion process.
${PROMOTED_*} variables
As you state the normal build variables refer to the promotion process itself, but The Promoted Build Plugin defines some environment variables referring to the actual build instead.
Permalinks
In a Jenkins context permalinks only refers to the special links that points to the latest build of some type or the latest promotion. That is why you will always get the latest version
In my version of Jenkins the dropdown is replaced with a textbox. Writing the URL to a specific build like http://jenkins/job/myjob/59/
is not recognized as one of the special permalinks, and the copying will thus fail.