feat(pipeline): add credentials support for semantic release in SemanticReleasingExecutor

Signed-off-by: 孙振宇 <>
This commit is contained in:
孙振宇 2025-02-08 10:20:52 +08:00
parent 80dd57433c
commit d8f04dda6d
2 changed files with 13 additions and 10 deletions

View File

@ -19,19 +19,22 @@ class SemanticReleasingExecutor {
this.config = 'com/freeleaps/devops/builtins/semantic-release/releaserc.json' this.config = 'com/freeleaps/devops/builtins/semantic-release/releaserc.json'
} }
def release() { def release(credentialsId) {
steps.log.warn("SemanticReleasingExecutor", "Configuration file customization is not supported yet, using builtin release rules as fallback") steps.log.warn("SemanticReleasingExecutor", "Configuration file customization is not supported yet, using builtin release rules as fallback")
steps.log.info("SemanticReleasingExecutor", "Releasing with config: ${config}") steps.log.info("SemanticReleasingExecutor", "Releasing with config: ${config}")
steps.dir(steps.env.workroot) { steps.dir(steps.env.workroot) {
steps.writeFile file: 'releaserc.json', text: steps.libraryResource(config) steps.withCredentials(credentialsId: credentialsId, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME') {
steps.log.info("SemanticReleasingExecutor", "Installing semantic-release requirements...") steps.env.GIT_CREDENTIALS = "${steps.env.GIT_USERNAME}:${steps.env.GIT_PASSWORD}"
steps.sh "apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates curl wget gnupg" steps.writeFile file: 'releaserc.json', text: steps.libraryResource(config)
steps.log.info("SemanticReleasingExecutor", "Installing semantic-release plugins...") steps.log.info("SemanticReleasingExecutor", "Installing semantic-release requirements...")
steps.sh "npm install -g ${plugins.join(' ')}" steps.sh "apt-get -y update && apt-get install -y --no-install-recommends git apt-transport-https ca-certificates curl wget gnupg"
steps.sh "semantic-release" steps.log.info("SemanticReleasingExecutor", "Installing semantic-release plugins...")
steps.log.info("SemanticReleasingExecutor", "Semantic release completed, read latest version from VERSION file") steps.sh "npm install -g ${plugins.join(' ')}"
steps.env.LATEST_VERSION = steps.readFile('VERSION').trim() steps.sh "semantic-release"
steps.log.info("SemanticReleasingExecutor", "Semantic release completed, read latest version from VERSION file")
steps.env.LATEST_VERSION = steps.readFile('VERSION').trim()
}
} }
} }
} }

View File

@ -265,7 +265,7 @@ def generateComponentStages(component, configurations) {
def sourceFetcher = new SourceFetcher(this) def sourceFetcher = new SourceFetcher(this)
sourceFetcher.fetch(configurations) sourceFetcher.fetch(configurations)
def semanticReleasingExecutor = new SemanticReleasingExecutor(this, env.workroot + "/" + component.root + "/") def semanticReleasingExecutor = new SemanticReleasingExecutor(this, env.workroot)
semanticReleasingExecutor.release() semanticReleasingExecutor.release()
} }
} }