how could I execute a npm install and ng build commnad line after a git push trought Jenkins? Please condiser that i am using BitBucket as a remote repository.
thanks in advance. Andrea
Go to Manage Jenkins -> Global Tool Configuration -> GitAdd git executable path to Global Tool Configuration. Let us start with creating a Freestyle Project : Step 1: Go to New Item -> create a freestyle project. Step 2: Go to Configure, add a project description, and Github project URL.
Please follow below steps to setup npm install and auto build via Jenkins.
Please find below screen shot for better understanding
To automatically run builds, Jenkins listens for POST requests at a Hook URL. You need to give this URL to the repository on GitHub. Then, whenever code is pushed to that repository, GitHub will send a POST request to the Hook URL and Jenkins will run the build.
To get the Hook URL of Jenkins, Open the Jenkins Dashboard.
Go to: Manage Jenkins > Configure System
Under GitHub Plugin Configuration, Click on ‘Advanced…’ Check ‘Specify another hook url for GitHub configuration’ A textbox will appear with a hook URL. This is the Hook URL at which Jenkins will listen for POST requests. Open your repository on GitHub.
Click ‘Settings’ on the navigation bar on the right-hand side of the screen. Click ‘Webhooks & services’ on the navigation bar on the left-hand side of the screen. Paste the URL you copied in the previous step as the ‘Payload URL’. You can select the events for which you want the Jenkins build to be triggered. We will select ‘Just the push event’ because we want to run the build when we push our code to the repository Alternatively, you can click on ‘Let me select individual events’ to get a list of all the events that you can select to trigger your Jenkins build.
Click ‘Add webhook’ to add the webhook. In Jenkins, go to the project configuration of the project for which you want to run an automated build.
In the ‘Build Triggers’ section, select ‘Build when a change is pushed to GitHub’. Save your project.
Jenkins will now run the build when you push your code to the GitHub repository These are the steps to execute a shell script in Jenkins:
Adding angular build script in jenkins: In the main page of Jenkins select New Item. Enter an item name like "my shell script job" and chose Freestyle project. Press OK. On the configuration page, in the Build block click in the Add build step dropdown and select Execute shell. In the textarea you can either paste a script or indicate how to run an existing script. So you can either say:
npm install ng build --prod --aot
or just
/path/to/your/script.sh Click Save. Now whenever you push in github your project will be deployed with new changes. Hope it help :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With