Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

jenkins - How to display application build version in an angular application

I have a jenkins pipeline which builds & deploy an angular application. Is it possible to introduce a build parameter from Jenkins during build and display it in the angular application?

Edit: The purpose is to introduce a parameter at the build time in jenkins pipeline which will take input during build time for describing the issue (for example: JIRA number of an issue) for which this build is getting created. It is then needed to display this issue/bugfix number in the angular application so that the user can see this fix number in the application footer and is sure about the fix deployed in the application. I hope to clarify the problem.

I started with available environment variable build number to start with & tried to use following script in Jenkins pipeline script stage('Replace'){ agent any when { environment name: 'showVersionCheckout', value: 'true'} steps {

            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xyz', url: 'https://abcd.git']]])
                script {
                    sh "sed -i -e 's/VERSION/${env.version}/g' src/environments/environment.dev.ts"
                }
            }
    }

In Angular app: export const environment = { production: false, VERSION: '0.0.2' } So when the Jenkins pipeline builds the angular application, i still see the old value of 0.0.2 instead of what we replaced using sed. Can anyone help ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not exactly what you asking for but i do the following in my applications. I have a custom webpackconfig and define theses variables:

module.exports = {
    plugins: [
        new webpack.DefinePlugin({
            'APP_VERSION': JSON.stringify(packageJSON.version),
            'APP_LASTCOMMIT': JSON.stringify(childProcess.execSync('git rev-parse HEAD').toString())
        })
    ]
}

environment.ts:

declare var APP_VERSION;
declare var APP_LASTCOMMIT;
export const environment = {
    appName: 'WebCommander-DEV',
    appVersion: APP_VERSION,
    appLastCommit: APP_LASTCOMMIT,
    production: false,
};

Im sure you can adjust this procedure to pass your jenkins build-id into the building process


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...