Is there a plugin to rename a build in Jenkins based on a variable in "Parameterised build"? I tried Build+Name+Setter+Plugin, but it has note in the help section that says
Blockquote
${ENV,var="VARIABLENAME"}
Expands to an environment variable (specified here as VARIABLENAME) from the build environment. Note that this does not include any variables set by the build scripts themselves, only those set by Jenkins and other plugins.
So the format #$jiraissue-${BUILD_NUMBER} (Where jiraissue is parameter passed to the build) didn't work when I tried it. Any suggestions?
I am not a Pro in Jenkins CI but this might be something of your interest.
Build Name Setter Plugin
This worked :)
${BUILD_NUMBER}-${ENV,var="jiraissue"}
Related
I'm trying to create a tag for each docker image generated with a jenkins job, for this I'm looking of how can I call an environment variable from jenkins such as build_number on my package.json
Thank you for your help.
You can build your docker image from Jenkins job using following command.
docker build -f Dockerfile -t react-image:${env.BUILD_NUMBER} .
It is not clear whether you want a version number defined inside package.json or the jenkins build number as the previous answer gave you.
In case you want a version number defined inside your package.json you could fetch it with grep inside a jenkins shell command and then use docker build as the above answer suggested.
If the version/build number is simply a shell environment variable, then you could use the environment variable injection plugin to export it to Jenkins.
Currently I am developing a react application. I have created a .env file and am using the environment variables in all other pages but am not able to see the .env file in the build folder. Is there any way to change the environment variables at run time in the build file?
This will work when changing the hostname and port, etc. manually and then cresting the build. Is there any way to change the variables after creation of the build?
Any help will appropriated.
Thanks,
Riya
The answer to your question can be found here:
Create React App Docs: Adding Custom Environment Variables
The environment variables are embedded during the build time. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like described here. Alternatively you can rebuild the app on the server anytime you change them.
My console keeps on saying that
"To set up the editor integration, add something like REACT_EDITOR=atom to the .env.local file in your project folder and restart the development server. Learn more"
I cant even find the .env file on my create-react-app.
Thank you in advance.
Create-React-App supports custom environment variables.
The documentation discusses how to declare these variables:
This can be done using two ways: either in your shell or in a .env file. Both of these ways are described in the next few sections.
Through the local environment
The first way is to add it to your local environment:
For instance, if you're using bash, edit ~/.bashrc
Add export REACT_APP_EDITOR=atom to the bottom then restart your terminal (or source ~/.bashrc)
Through .env files in your application
The second way is to create a .env file at the root of your application directory, and add the variable on a single line there:
REACT_APP_EDITOR=atom
From the documentation, these types of files can be declared and will be consumed by Create-React-App:
.env: Default.
.env.local: Local overrides. This file is loaded
for all environments except test.
.env.development, .env.test, .env.production: Environment-specific
settings.
.env.development.local, .env.test.local, .env.production.local: Local
overrides of environment-specific settings.
I'm using Jenkins ver 2.121.2. I'm trying to configure the Groovy plugin to run groovy scripts via a Jenkins job. The plugin documentation provided here
does not appear to match the UI I see in the System Configuration - Groovy section of this version of Jenkins. The various parameters don't match and so far I'm unable to get the plugin to run a simply groovy script. Not being familar with java and how the classpath works I'm not able to loosely interpret the instructions and get it working. If anyone can point me at documentation that more closely matches the Groovy plugin with the most current version of Jenkins I would appreciate it.
First, you need to configure an instance (or instances) of Groovy to run scripts in your builds. You do that on the Global Tool Configuration page.
You should have a least one JDK configured in the Global Tools Configuration (or have JAVA_HOME defined).
You can have Jenkins install the version of Groovy you want (on first use), or you can install Groovy yourself and point to it as in the example below:
Once this is in place, you can use the Execute Groovy Script build step in a build:
I am using create-react-app, Travis CI and netlify. I have a config file that looks like this:
require('dotenv').load();
module.exports = {
API_BASE_URL: process.env.REACT_APP_DATABASE_URL || 'http://localhost:8080'
}
When I try to deploy to Netlify, I get this error in Travis:
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/dotenv/lib/main.js:23
If I remove the require('dotenv').load(); part, it loads, but then the app tries to go to localhost, which is obviously not what I want.
This article: https://github.com/motdotla/dotenv/issues/261
brings up the same issue, but they don't offer a solution. I'm stuck. Help!
disclaimer: I work for netlify.
TL;DR unix shells complicate things.
The preferred way to use environment variables in Netlify is to set them in our environment - be that in the Build Environment Variables configuration widget (second on the "Build & Deploy settings" page - under your the repo+build command section), or via netlify.toml (https://www.netlify.com/docs/continuous-deployment/#deploy-contexts). The latter is a bit more flexible as you can set different values for different contexts - e.g. staging uses a staging DATABASE_URL and production uses a production one.
So - those variables are "available" in the build environment - if your build command were env, then you'd see them - in addition to $PATH and $NODE_VERSION and some other stuff Netlify sets automatically. However, depending on how your build pipeline works, they may or not be available inside of it. If your build command is node -p "process.env" - that will show you what node sees for environment variables - and that should show the same thing as env shows (which is what the shell run by the build script sees).
Unfortunately, many of the build pipelines that folks use DON'T automatically import/inherit variables from the parent shells. This thread shows such an example: https://github.com/theintern/intern/issues/136#issue-26148596 . So - the best practice is not to necessarily use something like dotenv (though that has worked for folks that aren't trying to minify it :) ) - but instead, use a build process that appropriately passes those environment variables that we expose in the shell, into the build environment. How you do that is kind of up to you and your tools.
a further PS: unless your build pipeline DOES something with the environment variable - it's not going to be much use in the code that gets published and served to the browser - which doesn't understand $REACT_APP_DATABASE_URL - that's just a string to the browser. I know you're not trying to do that, but wanted to point it out for folks who might see this answer later - it's a common misunderstanding among newer developers of static sites.