PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label jenkins. Show all posts
Showing posts with label jenkins. Show all posts

Saturday, November 5, 2022

[FIXED] What environment variables are passed to Jenkins when using the Gerrit Trigger Plugin?

 November 05, 2022     environment-variables, gerrit, jenkins, triggers     No comments   

Issue

I'm using the Gerrit Trigger Plugin to kick off Jenkins builds, but haven't found a good place where all of the environment variables are documented. Does such documentation exist?


Solution

As a start, I had a Jenkins build shell script dump all environment variables with GERRIT in the name:

GERRIT_PATCHSET_UPLOADER=\"Alan Thompson\" <theEmail@gmail.com>
GERRIT_PATCHSET_REVISION=eec3b0b65fcdf30872befa2e9ace06e96cd487b4
GERRIT_CHANGE_ID=Ieec3b0b65fcdf30872befa2e9ace06e96cd487b4
GERRIT_PATCHSET_NUMBER=1
GERRIT_EVENT_ACCOUNT_EMAIL=theEmail@gmail.com
GERRIT_CHANGE_NUMBER=8
GERRIT_CHANGE_OWNER=\"Alan Thompson\" <theEmail@gmail.com>
GERRIT_REFSPEC=refs/changes/08/8/1
GERRIT_EVENT_TYPE=change-merged
GERRIT_EVENT_ACCOUNT=\"Alan Thompson\" <theEmail@gmail.com>
GERRIT_CHANGE_SUBJECT=toast:  this is great with coffee
GERRIT_CHANGE_OWNER_NAME=Alan Thompson
GERRIT_PROJECT=kitchen
GERRIT_EVENT_HASH=-1357519550
GERRIT_BRANCH=master
GERRIT_CHANGE_OWNER_EMAIL=theEmail@gmail.com
GERRIT_PATCHSET_UPLOADER_EMAIL=theEmail@gmail.com
GERRIT_CHANGE_URL=http://localhost/8
GERRIT_PATCHSET_UPLOADER_NAME=Alan Thompson
GERRIT_EVENT_ACCOUNT_NAME=Alan Thompson


Answered By - Alan Thompson
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, October 18, 2022

[FIXED] How to extract coverage report in multistage build?

 October 18, 2022     docker, docker-build, docker-buildkit, docker-multi-stage-build, jenkins     No comments   

Issue

I want to extract the coverage report while building a docker image in a multistage build. Before I was executing the tests via image.inside using the Jenkins Docker plugin but now I am executing the tests using the following command where I could not extract the coverage report.

docker build -t myapp:test --cache-from registry/myapp:test --target test --build-arg BUILDKIT_INLINE_CACHE=1 .

Is there any way to mount the Jenkins workspace like the below function is doing without running the docker image? There is a --output flag but I could not understand how can I use this if it works. Or can it be possible via RUN --mount=type ...

  image.inside('-u root -v $WORKSPACE/coverage:/var/app/coverage') {
      stage("Running Tests") {
        timeout(10) {
          withEnv(["NODE_ENV=production"]) {
            sh(script: "cd /var/app; yarn run test:ci")
        }

Dockerfile

FROM node:16.15.0-alpine3.15 as base
WORKDIR /var/app
RUN --mount=type=cache,target=/var/cache/apk \
    apk add --update --virtual build-dependencies build-base \
    curl \
    python3 \
    make \
    g++ \
    bash 
COPY package*.json ./
COPY yarn.lock ./
COPY .solidarity ./
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn && \
    yarn install --no-progress --frozen-lockfile --check-files && \
    yarn cache clean
COPY . .

FROM base as test
ENV NODE_ENV=production
RUN ["yarn", "run", "format:ci"]
RUN ["yarn", "run", "lint:ci"]
RUN ["yarn", "run", "test:ci"]

FROM base as builder
RUN yarn build

FROM node:16.15.0-alpine3.15 as production
WORKDIR /var/app
COPY  --from=builder /var/app /var/app
CMD ["yarn", "start:envconsul"]

Solution

You can make a stage with the output you want to extract:

FROM node:16.15.0-alpine3.15 as base
WORKDIR /var/app
RUN --mount=type=cache,target=/var/cache/apk \
    apk add --update --virtual build-dependencies build-base \
    curl \
    python3 \
    make \
    g++ \
    bash 
COPY package*.json ./
COPY yarn.lock ./
COPY .solidarity ./
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn && \
    yarn install --no-progress --frozen-lockfile --check-files && \
    yarn cache clean
COPY . .

FROM base as test
ENV NODE_ENV=production
RUN ["yarn", "run", "format:ci"]
RUN ["yarn", "run", "lint:ci"]
RUN ["yarn", "run", "test:ci"]

FROM scratch as test-out
COPY --from=test /var/app/coverage/ /

FROM base as builder
RUN yarn build

FROM node:16.15.0-alpine3.15 as production
WORKDIR /var/app
COPY  --from=builder /var/app /var/app
CMD ["yarn", "start:envconsul"]

Then you can build with:

docker build \
  --output "type=local,dest=${WORKSPACE}/coverage" \
  --target test-out .


Answered By - BMitch
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, October 9, 2022

[FIXED] How to show results of individual test pass/fail in Jenkins?

 October 09, 2022     automated-tests, continuous-integration, jenkins, jenkins-plugins     No comments   

Issue

We're using Scala + Maven + ScalaTest runner + Jenkins. We have JUnit-style XML output going here:

test_dir/target/scalatest-reports/

Right now we can see entire build pass/fail, or dig through the verbose Console Output to see test pass/fail (not ideal), but I'm sure there's a better way.

I've tried several of the post-build steps such as:

  • Aggregate downstream test results
  • Publish xUnit test result report

But can't get a table of test results working.


Solution

You should better describe your symptoms. JUnit-style XML report is the basic form of test report supported by Jenkins/Hudson, so I suppose the problem is relatively simple. Please compare your configuration with the following example:


enter image description here


I would suggest the following:

  1. Check you configuration (it is likely jenkins is not able to find the actual report file)
  2. Look through the console output to make sure there is no warning message related to XML report file
  3. Verify XML report is not empty and valid
  4. Try to use JUnitReport tasks to generate HTML form
  5. Finally, switch to TestNG if you can


Answered By - Renat Gilmanov
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to run jenkins as a different user

 October 09, 2022     continuous-integration, jenkins     No comments   

Issue

I have been trying to follow tutorials and this one: Deploy as Jenkins User or Allow Jenkins To Run As Different User?

but I still can't for the love of the computing gods, run as a different user. Here are the steps of what I did:

  1. download the macosx pkg for jenkins(LTS)
  2. setup plugins etc and git
  3. try to build it

I keep getting a can't clone error because jenkins keeps starting as anonymous:

Started by user anonymous

How do I set it up so that jenkins runs as me? I was using the jenkins web UI so it was in localhost:8080

I tried logging in also using /login but I can't even login using my name or as root.

The people tab doesn't even have a create user link, so yeah I've been stuck. Help please?


Solution

ISSUE 1:

Started by user anonymous

That does not mean that Jenkins started as an anonymous user.

It just means that the person who started the build was not logged in. If you enable Jenkins security, you can create usernames for people and when they log in, the

"Started by anonymous" 

will change to

"Started by < username >". 

Note: You do not have to enable security in order to run jenkins or to clone correctly.

If you want to enable security and create users, you should see the options at Manage Jenkins > Configure System.


ISSUE 2:

The "can't clone" error is a different issue altogether. It has nothing to do with you logging in to jenkins or enabling security. It just means that Jenkins does not have the credentials to clone from your git SCM.

Check out the Jenkins Git Plugin to see how to set up Jenkins to work with your git repository.

Hope that helps.



Answered By - Sagar
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I clear my Jenkins/Hudson build history?

 October 09, 2022     build-automation, continuous-integration, hudson, jenkins     No comments   

Issue

I recently updated the configuration of one of my hudson builds. The build history is out of sync. Is there a way to clear my build history?

Please and thank you


Solution

If you click Manage Hudson / Reload Configuration From Disk, Hudson will reload all the build history data.

If the data on disk is messed up, you'll need to go to your %HUDSON_HOME%\jobs\<projectname> directory and restore the build directories as they're supposed to be. Then reload config data.

If you're simply asking how to remove all build history, you can just delete the builds one by one via the UI if there are just a few, or go to the %HUDSON_HOME%\jobs\<projectname> directory and delete all the subdirectories there -- they correspond to the builds. Afterwards restart the service for the changes to take effect.



Answered By - William Leara
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to configure Jenkins to run on port 80

 October 09, 2022     continuous-integration, hudson, jenkins, ubuntu, upstart     No comments   

Issue

I'm running Ubuntu 11.10 and have run sudo apt-get install jenkins to install Jenkins on this system.

I've seen some tutorials on how to setup a reverse proxy (Apache, Nginx, etc), however this is a VM dedicated for just jenkins and I'd like keep it as lean as possible while having jenkins running on port 80.

I've found the upstart config in /etc/init/jenkins.conf and modified the port to 80 env HTTP_PORT=80

When I start jenkins via service jenkins start, ps reveals that it runs for a few seconds then terminates.

Is this because jenkins is running as the jenkins user on a privileged port? If so, how do I fix this? Any other ideas a welcome.

Here is the upstart config:

description "jenkins: Jenkins Continuous Integration Server"
author "James Page <james.page@ubuntu.com>"

start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]

env USER="jenkins"
env GROUP="jenkins"
env JENKINS_LOG="/var/log/jenkins"
env JENKINS_ROOT="/usr/share/jenkins"
env JENKINS_HOME="/var/lib/jenkins"
env JENKINS_RUN="/var/run/jenkins"
env HTTP_PORT=80
env AJP_PORT=-1
env JAVA_OPTS=""
env JAVA_HOME="/usr/lib/jvm/default-java"

limit nofile 8192 8192

pre-start script
    test -f $JENKINS_ROOT/jenkins.war || { stop ; exit 0; }
    $JENKINS_ROOT/bin/maintain-plugins.sh   
    mkdir $JENKINS_RUN > /dev/null 2>&1  || true
    chown -R $USER:$GROUP $JENKINS_RUN || true
end script

script
    JENKINS_ARGS="--webroot=$JENKINS_RUN/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT"
    exec daemon --name=jenkins --inherit --output=$JENKINS_LOG/jenkins.log --user=$USER \
        -- $JAVA_HOME/bin/java $JAVA_OPTS -jar $JENKINS_ROOT/jenkins.war $JENKINS_ARGS \
        --preferredClassLoader=java.net.URLClassLoader
end script

Solution

Give a try to 'authbind':

sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80 
sudo chown jenkins /etc/authbind/byport/80

Then modify the script above to have (add authbind before the $JAVA_HOME/bin/java part):

exec daemon --name=jenkins --inherit --output=$JENKINS_LOG/jenkins.log \
--user=$USER -- authbind $JAVA_HOME/bin/java $JAVA_OPTS \
-jar $JENKINS_ROOT/jenkins.war $JENKINS_ARGS \
--preferredClassLoader=java.net.URLClassLoader

For newer Jenkins installations (1.598) on newer Ubuntu installations (14.04) edit /etc/init.d/jenkins and add authbind before $JAVA

$SU -l $JENKINS_USER --shell=/bin/bash -c "$DAEMON $DAEMON_ARGS -- authbind $JAVA $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_ARGS" || return 2

As mentioned by Alan (see comment below) if you need IPv6 and your system is lower than Quantal you can instead of using apt-get to install authbind download a higher version. Make sure you have libc6 and libc6-udeb installed. Here is authbind version 2.1.1 from Ubuntu:

  • amd64
  • i386

Then execute:

sudo dpkg -i authbind_2.1.1_amd64.deb
# or sudo dpkg -i authbind_2.1.1_i386.deb

sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80 
sudo chown jenkins /etc/authbind/byport/80


Answered By - JScoobyCed
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, September 28, 2022

[FIXED] How to copy build XMLs from Master to the Slave node in Jenkins?

 September 28, 2022     continuous-delivery, continuous-deployment, continuous-integration, jenkins     No comments   

Issue

I have created a Jenkins job which used to run in the master and I have the build.xml file in the master.

Now I have added a slave node and added the setting Restrict where this project can be run so that my job always runs on a particular slave.

Now my build jobs are failing and I can see:

[EnvInject] - Loading node environment variables.
Building remotely on demo_slave_inst2 (slave1) in workspace /root/slave/workspace/demo_job
FATAL: Unable to find build script at /root/slave/workspace/demo_job/autobvt.xml
Build step 'Invoke Ant' marked build as failure
Recording test results
Finished: FAILURE

This autobvt.xml file already exists in the master. So looks like I need to copy this file over to the slave node manually which does not looks like quite handy.

How I can instruct jenkins to copy this as part of the build?


Solution

I sorted the issue using the Copy to Slave plugin.



Answered By - Exploring
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to implement continuous deployment with Nexus and Jenkins

 September 28, 2022     continuous-deployment, hudson, jenkins, nexus     No comments   

Issue

I'm trying to implement a continuous deployment system and I seem to not be able to find a good answer for our problem. We use Jenkins to run a maven build to generate our artifacts and deploy them to Nexus. I see a few projects that bundle up everything into a single war or tar file, extract one file per request from Nexus by name and deploy it to an application server, but this requires them to know beforehand what versions they have available. My project has quite a few jars/wars/binaries among other artifacts, which don't get deployed using an application server. What we want to do is be able to do is pull any snapshot or release revision of the software out of nexus and either generate an install package or deliver it directly to a remote server.

Clarification: I want QA or development to be able to select a version from Jenkins; where Jenkins will poll Nexus for the available versions, then perform an automated deploy to a server from Nexus.

Is there an easy nexus/maven way to get software out to a testing system?

So, is there a way to poll nexus to determine what revisions are available through ant/ivy, Jenkins, maven, gradle? I'll write in something else if it helps.

I see that a similar question was asked here: How do I choose an artifact from Nexus in a Hudson / Jenkins job?, but it is as of yet unanswered 9 months later.


Solution

Nexus gives you a standard HTTP browsing capability. You could browse the repository through HTTP and see what is available.

I still don't understand your Use Case though. If you know which versions of the project you want then what is the problem?

The easiest would be to write an installer pom.xml that has in it a ${} placeholder for the version you want for the artifacts then invoke mvn with mvn package -Dproduct.version=1.0.0

If you use a container, PAX has plugins that allow you to specific artifacts like mvn:myGroup/myArtifact/myVersion and it will auto pull from Maven.

Nexus isn't doing any magic. It's all well known paths on a URL of groups/artifactId/versions



Answered By - Andrew T Finnell
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to configure Jenkins for MasterJob to pass git tag to child jobs, which execute in parallel?

 September 28, 2022     continuous-deployment, continuous-integration, hudson, jenkins     No comments   

Issue

I've seen numerous questions on SO for similar issues, but I haven't found one that answers this question for me.

I'm looking for pretty much the simplest use case for parallel builds. I'd like to do the following:

Job1 (git commit no: abc123)
  |
  +------- SubJob1 (git commit no: abc123)
  |
  +------- SubJob2 (git commit no: abc123)

Both subjobs would be executed in parallel, and Job1 wouldn't complete until all subjobs finished.

Job1 gets executed by a git hook for a commit against any branch. At the moment the subjobs execute other commits instead of the exact one the parent job originally executed against.

Anyway to get this working?

As a bonus question, would it be possible for console output to be rolled up to the master job?

Thanks


Solution

You can achieve this with the MultiJob plugin which allows you to trigger phases of jobs (subjob1 and subjob2) in addition to any standard job building steps you want in the main job (job1)

You can also pass parameters into the subjobs Jenkins using File Parameter with MultiJob Project


EDIT the git parameter plugin may help to pass git revisions into jobs



Answered By - KeepCalmAndCarryOn
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What is the best Docker tagging strategy?

 September 28, 2022     continuous-deployment, continuous-integration, docker, jenkins     No comments   

Issue

It is certain, that "latest" tag is not enough (i.e. if you want to rollback/debug).

What is the best docker tagging practice? Is it better to tag it with build number or commit number? Or some other option?


Solution

We don't use tagging for development environment, because we have pretty nice test coverage, but I suggest, you can easily tag container with your CI tool build number (Teamcity, Jenkins), something like

docker build -t {yourserviceName}:{JENKINS BUILD NUMBER}

However, production deployments - is a little bit different story. We use two tags for that - previous and latest

1.Build production container on teh build server

2.Push it to shared repo

3.Pull to production server.

The latest tag is always contained at shared repository. Before step 3, just re-tag existing running container to previous.

What's the benefit?

If you have your latest container with critical failure, you just rollback to previous one. It's extremely rare case, when you have to do a rapid rollback, let's say, 4 deployments back, so no need to maintain versions there



Answered By - Andrew
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What is the state of the art of continuous integration vs feature branch as of early 2015?

 September 28, 2022     branch, continuous-deployment, continuous-integration, jenkins, teamcity     No comments   

Issue

I'm kind of new into the world of continuous integration.

Because i want to practice CI/CD properly i try to read about the best practices but it is quite of a puzzle to me.

I wonder if someone with experience could let me know as of today what is the state of the practice with respect to the following matter:

"Feature branch / branch by feature" and CI.

By this i mean that i found that the part in which people are struggling the most is actually about:

The practice of CI that requires frequent integration (in mainline) and the development practice that encourage feature driven development.

From what i red there is a tension between falling in feature isolation and integrating feature even if not finished.

Hence i would like to know, what is the state of that matter today.

I saw things like branch by abstraction and feature toggles, but also other solution that are not clear to me yet but who seem to relies on tools to manage some automatic merge, that first merge and test the branch, and merging it back in the main line.

Sounds like tool like Teamcity and Bomboo have support for that. Less clear on jenkins grounds.

Hence if one could help map out the state of the art for that specific issue i would appreciate


Solution

Mandatory disclosure: I'm the CTO and Co-founder of Bitrise, a CI/CD service (mainly) for mobile app developers.

What we usually recommend (and the practice what we use for in house app development) is to test every single code push, no matter which branch. Always try to push code which works / passes unit tests and of course write unit tests.

In most CI/CD services you can define a general test build which will be performed for every code push and a separate build configuration/process for deployment. You should have a base test build configuration which will test every code push and you should try to achieve a green build no matter which branch you work on.

A couple of CI/CD services offer pull-request testing without actually merging the pull-request, so that when you check the pull-request you can be sure that after the merge the tests will still pass. It's quite complicated though (the master branch's state can change even while you're reading the pull-request) and for this our team doesn't rely on these tests but simply do the merge and if it fails we fix it right away.

For a development setup like this you need at least two main branches and you always work on a feature branch. The two main branches are:

  • a development master branch: this is the branch the developers use to create new feature branches. In gitflow it's typically called develop.
  • a stable / production branch: this branch contains only stable, tested code, merged only from the development master branch and only if it's green/passing all the tests. In gitflow this branch is called master.

This branching strategy works well with most of the CI/CD services and is a good choice for mobile apps and SaaS services where you can and want to release frequently (at least for your testers / staging servers).



Answered By - Viktor Benei
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I incorporate a long delay into a Jenkins build process?

 September 28, 2022     continuous-deployment, jenkins, jenkins-plugins     No comments   

Issue

I am using Jenkins to deploy changes to a system which manages and runs lots of different jobs which are scheduled daily. We have a staging setup which does not write to the real database, and a production setup which does.

The Jenkins flow I would like to have a happen when a change is pushed is this

  1. Run checks.
  2. Deploy to the staging system.
  3. Wait 24 hours.
  4. Check logs to make sure that the staging system has not had any errors in the last 24 hours.
  5. Deploy to the production system.

There could be more than one of these builds running concurrently at any time - eg. I push changes at 11 am, they are deployed to staging. At 5 pm I push more changes and they are also deployed to staging. The next day at 11 am the first set of changes only are deployed to prod. At 5pm that day the second set of changes are deployed.

Now, I have managed to build a system which does this, by using the Build Flow Plugin, and creating a job called wait_one_day which runs sleep $((24 * 60 * 60)) in a bash shell.

This doesn't seem like the most elegant solution, and has the disadvantage that I am tying up two Build Executors for 24 hours (one for the build flow job, and one for wait_one_day), each time we make a change.

Is there any better way of doing this, or any plugin which is designed to help with this process? Can a Jenkins job schedule another Jenkins job to run as a one-off?

I would equally be happy to hear about an alternative approach to solve the same problem if anyone has any suggestions or constructive criticism of my design.


Solution

There was similar SO question recently that I answered, although I'm not sure that my answer there exactly fits your scenario.

You could potentially dynamically create a job that does steps 4 & 5 which would run periodically every 24 hours. The catch here is that you would actually only run this job once, and have a build step in that job that deletes itself (groovy code or shell script). It would be easy enough to create a deactivated template job that you could just clone and then modify for the particular task. An intermediary job would be necessary which would trigger upon completion of any job that runs steps 1 and 2. The intermediary job would then create the temporary job from the template.

Alternatively, you could create some sort of handler, either within jenkins or external that would run off of some properties file or database containing the scheduling for when jobs need to be fired off. Granted, if you are going to go the route of writing a handler, you might consider putting in a little extra effort and writing a jenkins plugin...



Answered By - TheEllis
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What are the pros and cons of using AWS Code Deploy Vs Jenkins?

 September 28, 2022     amazon-web-services, aws-code-deploy, continuous-deployment, continuous-integration, jenkins     No comments   

Issue

We are using a bunch of EC2 instances which might scale in the future (around 100 instances), now we are looking towards auto deployments using either Jenkins or AWS Code deploy.

I found that we can use AWS Code deploy plugin with Jenkins, but What are the pros and cons of following?

1) Standalone AWS Code Deploy 2) Jenkins with AWS Code Deploy plugin.


Solution

We use both CodeDeploy and Jenkins to manage deployments to our AWS environments.

They each have their roles, and I do not see it as a pro/con analysis. I believe you need BOTH to manage both continuous integration builds (Jenkins) and the process of deploying tested builds to your EC2 environments (CodeDeploy)

Here is our setup:

  1. Jenkins polls our SCM for changed. When a change occurs, the app is built, archived into a ZIP, and registered as a deployable artifact in CodeDeploy. We label the revision with the Jenkins build number - say app_6111.zip. Each build is sent the our code deployment bucket: s3:codedeploy-example-com/app

  2. In CodeDeploy we have an application configured, with deployment groups for each environment eg Testing, Production. Since we use #1, all our builds are always ready for immediately deployment. So with one or two clicks, we deploy revision app_6111.zip to a Testing server, for example.

For us, Jenkins is a swiss army knife of modern devops and continuous integration, testing and deployment. Its the backbone from which we can manage builds, testing and building deployment artifacts. We can integrate with all AWS services such as S3, CodeDeploy, Elastic Beanstalk etc.

To answer your specific questions:

I found that we can use AWS Code deploy plugin with Jenkins, but What are the pros and cons of following?

1) Standalone AWS Code Deploy

A standalone CodeDeploy will not be integrated with your build process. It must be configured to either a static S3 artifact that is manually uploaded, or a Github URL. Github is fine, but there is no concept of a build - it deploys from the master or other branch. You cannot easily roll back to a known build for example. Testing is not integrated. No ability to pipeline tasks/jobs.

2) Jenkins with AWS Code Deploy plugin.

This is the preferred approach IMHO. Use both tools. Build known and tested builds, then register the deployment to CodeDeploy. Life is good.



Answered By - Rodrigo Murillo
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I use Jenkins to deploy a project that depends on another project on GIT?

 September 28, 2022     continuous-deployment, continuous-integration, jenkins, jenkins-pipeline, jenkins-workflow     No comments   

Issue

I am absolutly new in Jenkins and I have the following problem.

I have 2 jobs representing 2 different projects which are related to each other.

In particular I have the following situation:

I have a main project named main-project: this is a Java EE project. Then I have a Flex project named client-project that represent the web client of the previous project.

Both these project are stored in a specific GIT repository (so I have a specific GIT repository for the main-project Java EE project and another specific repository for the client-project).

The 2 projects (on my local machine) are related in the following way:

The main-project contains the .swf file that represent the compiled version of the client-project.

Something like this:

\main-project\src\main\webapp\Main.swf

So as you can see into the \src\main\webapp** directory of my **main-project is manually putted the Main.swf file that represent the compilation of the Flex client-project.

Ok, so my problem is: I have 2 Jenkins jobs related to these project.

1) main-project-job: that is the Jenkins job that compile and deploy on the srver the main-project project.

2) client-project-job: this job I think should do nothing (it only retrieve the latest compiled version of the client-project project.

I have to automate the building process in this way:

After that a dveloper push on GIT a new version of the main-project project the main-project-job compile and deploy it on server. When this job ends start the client-project-job that replace the Main.swf file into the **\DEPLOYED-PROJECT\src\main\webapp** path on my deployed project on the server.

How can I do something like this using Jenkins? Is it a neat solution to keep synchronized the latest version of the main-project and of the client-project?


Solution

Here a few leads that you might want to explore.

1. Deploy main-project-job with the embedded swf

As your main-project seems to depend heavily on your swf file (it should probably not be deployed without the swf file), can't you just get and put the swf file as part of the compiled main-project artifact ? It would seem logical to mee that your deployed main-project already contains the swf file at the time it is deployed.

With Jenkins pipelines, something like this would be pretty easy to do :

stage("Build main project") {
    // your build step
}

stage("Copy client project to main webapp") {
    git 'your-git/client-project'
    sh "cp client-project/generated-swf /main-project/src/main/webapp/Main.swf"
}

stage("Deploy main project") {
    // your deploy step
}

2. Copy swf file as part of the main job

If you cannot integrate the swf file directly to the main-project before deploy, you could still use the same job to do that, again if the main project heavily depends on the swf file, you probably want to copy it as part of the job. In this case, only the copy step will change and you will need to use some scp command to copy the swf file to the deployed app, on the distant server.

Something along these lines :

stage("Build main project") {
    // your build step
}

stage("Copy client project to main webapp") {
    git 'your-git/client-project'
    sh "scp client-project/generated-swf user@deployServer:/main-project/src/main/webapp/Main.swf"
}

stage("Deploy main project") {
    // your deploy step
}

3. Copy swf file as part of a separate job

If you are sure that you want to make the copy action as part of another job (let's say, if you sometimes needs to manually trigger the job to copy the modified swf file in the running webapp, on the server), you can just trigger another job from the main-project-job :

main-project-job

stage("Build main project") {
    // your build step
}

stage("Deploy main project") {
    // your deploy step
}

stage("Copy client project to main webapp") {
    build job: copy-client-project
}

copy-client-project

stage("Copy client project to main webapp") {
    git 'your-git/client-project'
    sh "scp client-project/generated-swf user@deployServer:/main-project/src/main/webapp/Main.swf"
}

One last detail: if you do decide to use a separate job for copy, I would recommend not calling the job "client-project-job" which often implies a standard build/deploy job, instead I would name it "copy-client-files" or something similar.



Answered By - Pom12
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I retrieve the SVN Changeset comments for a Jenkins build?

 September 28, 2022     continuous-deployment, continuous-integration, jenkins, svn     No comments   

Issue

My process is that Jenkins polls SVN for a build every three minutes, performs a build when a change occurs, and creates a deployment package which it then pushes to Octopus. Once the deployment is complete, it sends a deployment report via email to everyone involved.

Right now, the build notes in the report are just typical boilerplate, i.e., Jenkins Build 35. What would be great would be if I could pull the comments for the changeset that triggered the build and build the release notes off of that.

If I can get AT the comments, getting them into the release notes is pretty simple. If anyone has any ideas on that, I would appreciate it.

UPDATE: There is a related question about how to do this with the email-ext plugin, but I'm not using that plugin, and as far as I can tell, the answer is expressed using the syntax of that plugin and I can't figure out how to adapt it. I would appreciate an answer that bears directly on my usage here.


Solution

There are 3 ways you can get the SCM changes

Groovy

Groovy is similar to Java and is native to Jenkins, hence you can reference Jenkins object models and data directly with Groovy. You still requires plugins to execute Groovy code, such as Groovy Plugin. Here is a bit of sample code adopted from this answer:
How to get the list of changed file in SVN from Jenkins

import hudson.model.*
import hudson.util.*
import hudson.scm.*
import hudson.scm.SubversionChangeLogSet.LogEntry

// work with current build
def build = Thread.currentThread()?.executable

// for testing, use last build or specific build number
//def item = hudson.model.Hudson.instance.getItem("Update_SRC_Branch") 
//def build = item.getLastBuild()   
//def build = item.getBuildByNumber(35)   

// get ChangesSets with all changed items
def changeSet= build.getChangeSet()
List<LogEntry> items = changeSet.getItems()

From there, the items list now contains the change set. Use as you wish. This is as far as I am going to go with Groovy, cause frankly I don't use it.

Filesystem

Jenkins stores builds on the filesystem under $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID. Prior to version 1.597, the $BUILD_ID was a timestamp in the format like 2015-03-16_00-13-19. After version 1.597, the $BUILD_ID is now a build number $BUILD_NUMBER like 123 (same as what you see in the build history log).

There is a file there: $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID/changelog.xml. It contains all the same SCM changesets that you see in the UI, pulled from your SCM, all in an XML file. Parse the file, and every <msg>...</msg> element contains the comments. There may be more than one.

However, although all the variables are available to you at runtime during the build (change $VAR to %VAR% if on Windows), the specific build location is NOT created till the build is completed, so you can't access it during the current build. You can however pass all these variables to a downstream build (for example your deployment job, if it is separate), and that downstream build can extract the changelog file. You would need Parameterized Trigger Plugin to pass variables to another build.

Email

The mailer action that comes with Jenkins can do almost nothing other than the "boilerplate" message. If you want anything to do with emails, you need the Email-ext (Extended Email) Plugin. There are a ton of questions/answers on SO here about email-ext, even a tag email-ext, however I would advise searching for text email-ext rather than using a tag, as a lot of questions are not fully tagged.

Your first place to start would be the "Content Token Reference" on-page help (click the ? icon next to that text. That lists all the possible tokens that can be used in the email title/body

You wanted the "SCM comments". Those are referenced through %m of ${CHANGES_SINCE_LAST_SUCCESS} token. To get just the comments, use the following:

${CHANGES_SINCE_LAST_SUCCESS, changesFormat=" %m<br>"}

Just put the above line into the email body configuration. You can surround it with any plain text you want.

For a more nicely formatted output, use

${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="<b>Changes for Build #%n</b><br>%c<br>", changesFormat="<br>[<a href='${JENKINS_URL}/user/%a/builds'>%a</a>] - (%r) %p<br> %m<br>"}

as referenced in the close duplicate questions I provided:
How can I get the SVN log entry in Jenkins when sending email

P.S.

If your requirement is "no plugins", then you need to find a different build system than Jenkins. Jenkins is an open-source project, that provides a core and a plugin for almost everything else, maintained by the open community. Everything in Jenkins is a "plugin", even the Subversion SCM step and Freestyle and Maven projects are "plugins". Some are bundled with the installation, most need to be added after the install.



Answered By - Slav
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to pass the additional parameter of slash command to jenkins job

 September 28, 2022     continuous-deployment, jenkins, slack     No comments   

Issue

Let's say I want to create a slash command with the flexibility to define the component as tag name which will be used for deployment.

eg: /dev-deploy comments v1.0.0

I have added the slash command as well as set the parameterized URL in

http://host/buildByToken/buildWithParameters?job=dev-deployment&token=test

All the other commands data is present in JSON object how can I access that data and pass it as a parameter to shell script which is executed when the build is triggered.


Solution

The slash command from Slack is sending a POST request to your URL. This request contains a property named text, which in your example would be "comments v1.0.0". To extract the tag you would need to parse it.

I would recommend to use some simple script (e.g. PHP) to receive the POST request, parse it (maybe also do some security checks) and then start the job with a shell command.

I am not sure what JSON object you are referring to. The slash command does not send any JSON. So maybe your question is missing some vital information? If so please add.

Here is an example of the POST request (from the official Slack documentation):

token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
enterprise_id=E0001
enterprise_name=Globular%20Construct%20Inc
channel_id=C2147483705
channel_name=test
user_id=U2147483697
user_name=Steve
command=/weather
text=94070
response_url=https://hooks.slack.com/commands/1234/5678


Answered By - Erik Kalkoken
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to trigger XL Release task from Jenkins ? Is it possible?

 September 28, 2022     continuous-deployment, continuous-integration, jenkins, xlrelease     No comments   

Issue

I have a CI pipeline configured on Jenkins. When the jobs execute successfully, I want a trigger to pass on to XL Release so that it automatically triggers the deployment process. Is this possible ?


Solution

There's the Jenkins-XLR plugin that you can install straight from Jenkins. In Jenkins, go to Manage Jenkins > Manage Plugins and search for the XL Release plugin.

The plugin page is here: https://wiki.jenkins-ci.org/display/JENKINS/XL+Release+Plugin

Some more information can be found in this blog post.



Answered By - Hes Siemelink
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to include domain user in Jenkins Job execution

 September 28, 2022     continuous-deployment, dns, jenkins, powershell, windows     No comments   

Issue

I am automating a build process. The process requires deployment of application to a server, after deployment a few scripts have to be executed to share and provide permissions on the server. The scripts run when I login via domain user through powershell.I am using Jenkins for the CI/CD process. I want to include my domain credentials to run the scripts on the server. I have also used the active directory plugin, and can login with my domain credentials but still I am not able to establish a remote connection with the server.

My script is

Enter-PSSession -ComputerName ATKT-WS-20
Invoke-Expression -Command .\FolderSharingScript.ps1 

Enter-PSSession : Connecting to remote server ATKT-WS-20 failed with the following error message : WinRM cannot process the request. The following error with errorcode 0x8009030e occurred while using Kerberos authentication: A specified logon session does not exist. It may already have been terminated.
Possible causes are: -The user name or password specified are invalid. -Kerberos is used when no authentication method and no user name are specified. -Kerberos accepts domain user names, but not local user names. -The Service Principal Name (SPN) for the remote computer name and port does not exist. -The client and remote computers are in different domains and there is no trust between the two domains. After checking for the above issues, try the following: -Check the Event Viewer for events related to authentication. -Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport. Note that computers in the TrustedHosts list might not be authenticated.<

I have also added the machine name in the trustedhosts. How can I include the domain credential in Jenkins jobs?


Solution

The solution turned out to be not to use PowerShell's remoting at all, but instead rely on the remoting built into Jenkins:

  • Connect the remote machine as a Jenkins agent to the Jenkins server, running the agent executable as the desired domain user.

  • On the Jenkins server, ensure that your job is configured to run on the remote machine, using a label expression.

  • Assuming the PowerShell plugin is installed, you can then send PowerShell code as-is to the remote machine - no need for PowerShell sessions, credentials, ...



Answered By - mklement0
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, September 27, 2022

[FIXED] How to start deployment with email authentication in jenkins?

 September 27, 2022     continuous-deployment, continuous-integration, jenkins, jenkins-plugins     No comments   

Issue

We have a CI jenkins platform and we want to manage our deployments with an email confirmation. A user send a request to the deployment plan for starting. But in the first step, the plan send an email confirmation to an administrator. If the admin click the request link, deployment will be start, otherwise wont start.

Is there a way to do this with jenkins or any jenkins plugin?


Solution

yes there is a way to do that, honestly, more than one way to do that and you can choose by your preferneces. What I will suggest you is to consider the way explained in the issues of Jenkins https://issues.jenkins-ci.org/browse/JENKINS-33793

though it have status Unresolved, but it looks like by my knowledge that it will work even right now , cause it is just an URL.



Answered By - BigGinDaHouse
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What is the purpose of a build agent in continuous integration and continuous deployment?

 September 27, 2022     continuous-deployment, continuous-integration, jenkins, teamcity     No comments   

Issue

What is the purpose of a build agent in continuous integration (CI) and continuous deployment? Is this something that impacts all CI servers (e.g. Jenkins, TeamCity, TFS, etc.)

On the TeamCity license types page I noted that the professional server license, which is free, only includes three build agents.

https://www.jetbrains.com/teamcity/buy/#license-type=new-license


Solution

The expression build agent basically describes an environment in which builds or jobs of the CI pipeline are run. There are multiple synonyms for this part of the CI infrastructure. TeamCity seems to define a build agent as an environment where one build at a time can run.

Jenkins would define the machine which runs builds as a slave with a (different) master machine that coordinates which builds runs where. Multiple builds can run on the same slave in Jenkins in different executor slots.

Another system using a build agent is a Team Foundation server which should be structured similarly to TeamCity's solution. There has already been a more detailed answer here.



Answered By - Bricktop
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing