I am trying to modify Jenkinsfile to bump the version of my NPM package before deploying the server.
I have this on the deploy method:
if (env.GIT_COMMIT != env.GIT_PREVIOUS_COMMIT && env.GIT_BRANCH == "origin/develop"){
def version=sh(returnStdout: true, script: "npm version")
echo "Version is ${version}"
echo "${version.test}"
sh "npm version patch"
sh "git push"
}
I am checking if my previous commit is different than the actual, so if there is any change between the last deploy and the current, it should increase the version number.
The version variable output is:
{
test: '0.0.3',
npm: '6.12.1',
ares: '1.15.0',
brotli: '1.0.7',
cldr: '35.1',
http_parser: '2.8.0',
icu: '64.2',
llhttp: '1.1.4',
modules: '72',
napi: '5',
nghttp2: '1.39.2',
node: '12.13.1',
openssl: '1.1.1d',
tz: '2019c',
unicode: '12.1',
uv: '1.33.1',
v8: '7.7.299.13-node.16',
zlib: '1.2.11'
}
I would like test to go from 0.0.3 to 0.0.4 and then use npm version 0.0.4 to set that version in the app.
${version.test} is not working. It throws the following error:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.String test
How can I get that value and increase it so I can use properly the npm version 0.0.X and then pushing it to the repository?
Thanks in advance.
Related
After following the solution on github, and the solution on Stack Overflow, I am still experiencing the same issue when building a code pipeline with AWS CDK.
Error:
This CDK CLI is not compatible with the CDK library used by your application. Please upgrade the CLI to the latest version.
(Cloud assembly schema version mismatch: Maximum schema version supported is 21.0.0, but found 22.0.0)
This error appears in the Code Build Stage of the Code Pipeline. Sourcing the code from Code Commit works successfully, as the first stage.
CDK Pipeline Code:
As you can see in the code below, I have the install commands of uninstalling the cdk, and then installing it again. This was the recommended solution provided by the document above. Re-ordering does not influence the outcome.
this.codePipeline = new CodePipeline(this, `${environment}-${appName}-`, {
pipelineName: `${environment}-${appName}-`,
selfMutation: true,
crossAccountKeys: false,
role: this.codePipelineRole,
synth: new ShellStep("Deployment", {
input: CodePipelineSource.codeCommit(this.codeRepository, environment, {
codeBuildCloneOutput: true
}),
installCommands: ["npm uninstall -g aws-cdk", "npm i -g npm#latest", "npm install -g aws-cdk"],
commands: [
"cd backend",
"npm ci",
"npm run build",
"npx cdk synth",
],
primaryOutputDirectory: "backend/cdk.out",
})
});
Dependencies in the package.json file:
"dependencies": {
"#aws-cdk/aws-appsync-alpha": "^2.55.1-alpha.0",
"aws-cdk-lib": "^2.58.0",
"aws-sdk": "^2.1278.0",
"constructs": "^10.1.204",
"git-branch": "^2.0.1",
"source-map-support": "^0.5.21"
}
The solution was to do without the npx in npx cdk synth. I removed it and the code worked. This was also experienced when attempting to run npx cdk synth locally.
Solution: cdk synth
I am creating a blogsite with Gatsby and Contentful for learning purposes. I want to deploy my site to surge using Github actions. I am using gatsby-source-contentful plugin to get my content from Contentful at build time. The plugin requires spaceId and accessToken to access my Contenful space. During development at my local machine, I am providing these values to the plugin using environment variables saved in a .env file.
However, during the build process in Github actions, I am getting this error:
success open and validate gatsby-configs - 2.325s
error Invalid plugin options for "gatsby-source-contentful":
- "accessToken" is required
- "spaceId" is required
not finished load plugins - 1.002s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-contentful-blogsite#0.1.0 build: `tsc && gatsby build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-contentful-blogsite#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-02-18T17_53_11_281Z-debug.log
Error: Process completed with exit code 1.
Is there a way to tell Github actions about these environment variables (spaceId and accessToken) so that the gatsby-source-contentful plugin can be configured successfully?
Contentful DevRel here. 👋
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: `your_space_id`,
// Learn about environment variables: https://gatsby.dev/env-vars
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
},
},
],
}
In your gatsby config you can specify your environment variable such as above. Then in your GitHub repo you can define a secret and expose it as environment variable. You can find more information in the Github actions docs. Once you exposed the environment variable via the secret to the action, it should work fine.
Here is my pipeline jenkins
pipeline {
agent any
stages{
stage('clone and clean repo'){
steps {
bat "git clone https://github.com/developper-root/my-app"
bat "mvn clean -f my-app"
}
}
I have this error:
'mvn' is not recognized as an internal command
or external, an executable program or a batch file.
But, this command works
C:\Users\ASUS>mvn --version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T12:57:37+01:00)
Maven home: C:\Users\ASUS\Desktop\Esprit\Ressources JEE\Semaine 1\Outils - JEE\Maven\apache-maven-
3.3.3\bin\..
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_60\jre
Default locale: fr_FR, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
Kind regards.
Okay two things here.
When using -f flag you specify the pom.xml file so your command should be
mvn -f pom.xml clean package
Secondly if you're executing multiple line in bat file use below syntax
stage ('Build repo') {
steps {
bat '''
cd folder to pom.xml
mvn clean package
'''
}
}
It seems that MVN_HOME environment variable is not properly set. Are you running the script on Jenkins master directly? If so check if you have MVN_HOME set in Windows. If you are running this script on some slave, check if maven is installed on that machine.
I try to execute bower commands in a sh script that is run in the after-success phase o a travis build. I installed bower in the install phase:
install:
- npm install -g bower
[...]
after_success:
- if [ ${TRAVIS_PULL_REQUEST} = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
./my-script.sh;
fi
Unfortunately, if I call bower in the sh script it produces the following output:
./my-script.sh: line 30: ./node_modules/.bin/bower: No such file or directory
I do not know how to proceed to fix the error. Any help would be greatly appreciated, thank you already!
I had to call the script using
bash my-script.sh;
instead of
./my-script.sh;
Now everything is working fine.
I try to make nyc working with coveralls following the instruction:
https://github.com/istanbuljs/nyc#integrating-with-coveralls
But I can't get it to work. Here is an example repo:
https://github.com/unional/showdown-highlightjs-extension
Travis build is successful: https://travis-ci.org/unional/showdown-highlightjs-extension
And Coveralls notice the build, but does not seem to get any data:
https://coveralls.io/github/unional/showdown-highlightjs-extension
Here is my .travis.yml:
language: node_js
notifications:
email:
on_success: never
on_failure: change
node_js:
- "stable"
before_install:
- npm install -g npm
script:
- npm run verify
after_script:
- npm install coveralls && npm run coveralls
And here is my package.json:
{
...
"scripts": {
"coverage": "npm test && nyc check-coverage --branches 85 --functions 85 --lines 85",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"test": "npm run clean && tsc && nyc ava"
...
},
"nyc": {
"exclude": [
"scripts",
"**/*.spec.*",
"**/fixtures/**/*"
]
},
...
}
Try adding your Coveralls repo API token (which can be found on the Coveralls page for your repo) to a new COVERALLS_REPO_TOKEN encrypted environment variable on Travis, as per the (somewhat sketchy) documentation on the Coveralls site.
I found out the issue is in my tsconfig.json:
{
"compilerOptions": {
"sourceRoot": "/showdown-highlight-extension"
...
}
}
This setting gives me the correct (I assume) source map in the browser. See What's the proper way to set sourceRoot in typescript?
But is not liked by the coverage tool.
Once I remove it, it starts working.
Need to find an answer to that question.