Jenkins Fails to Install Packages for Angular Builds
Anytime your Angular project has changed Angular CLI versions, it is quite possible that the Jenkins job will fail, because its latent working copy has a different (older) Angular version cached in it.
NOTE: This article was written when our Jenkins server only built for one Angular version target.
So, it may need updating for cleaning up project-scoped Angular versions.
To fix this, you could possibly delete the working copy from the Jenkins workspace. Haven’t tried that yet.
But, there are two commented out lines in the Jenkins pipeline scripts that will fix it.
Open the Jenkins pipeline script and find this block:
stage('Build Library')
{
steps
{
// Adapted from here: https://www.baeldung.com/ops/jenkins-pipeline-change-to-another-folder
// NOTE: This 'dir' command will switch the directory only for the steps inside it.
// After the block, the working directory reverts to the jenkinsfile folder.
dir("${solutionName}/workspace")
{
/* execute commands in the workspace directory */
// sh "ng update @angular/cli@15 --allow-dirty"
// sh "ng update @angular/core@15 --allow-dirty"
sh "npm run build-library"
}
}
}
Uncomment the two ng update lines, so Jenkins will update its working copy to the desired Angular version.
NOTE: Be sure to set the desired Angular version, where the above has ‘15’.
This should fix the build error.
NOTE: This is only required once to upgrade the Jenkins workspace. So, comment these lines back out after a successful build.
Other things to fix if this problem won’t go away:
If that doesn’t fix things, then whatever library you recently upgraded its Angular version may need to be manually built/packed/published outside of Jenkins, so it can properly pull in that library dependency with an acceptable Angular dependency version.
If the workspace that library is in, includes any other libraries, such as a Middle-Library, used for dependency testing, that intermediate library also must be built/packed/published outside of Jenkins, so any listed dependency on it uses the same Angular version that you upgraded to.
No Comments