The post Install Jenkins as a Service on CentOS 7 appeared first on Justin Silver.
]]>I have previously written about how to Install Jenkins on CentOS as a Service where it was necessary to write your own startup, shutdown, configuration, and init.d scripts. Luckily this is all much easier now as you can install the software directly from a yum
repository – you’ll just need to fetch the repo from http://pkg.jenkins-ci.org/redhat/jenkins.repo.
Make sure you have Java on your system, then fetch the yum repository and install Jenkins.
yum -y install java curl http://pkg.jenkins-ci.org/redhat/jenkins.repo -o /etc/yum.repos.d/jenkins.repo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key yum -y install jenkins
Since CentOS 7 uses Systemd, use it to start the service on reboot.
systemctl enable jenkins service jenkins start
This will start jenkins on port 8080 by default (you can change these settings in /etc/sysconfig/jenkins). Leaving it as is and setting up a reverse Nginx proxy is my preference. Once you load the Jenkins home page you will be prompted to enter a password located in a file on your system to continue the setup. Here is a sample of my Nginx configuration.
# jenkins is upstream listening on port 8080 upstream jenkins { server 127.0.0.1:8080 fail_timeout=0; } # nginx is listening on port 80 server { listen 80; server_name jenkins.example.com; location / { proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://jenkins; } }
Keep in mind that you may have issues initially proxying to Jenkins if SELinux is configured to block access to port 8080. If you try to load the site via Ngnix and get a “502 Bad Gateway” error, check out the /var/log/audit/audit.log
– you will probably see errors regarding Nginx connecting to your port. You can either add the port by hand, or do it automatically with audit2allow
.
mkdir ~/.semanage && cd ~/.semanage cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M semanage semodule -i semanage.pp
If you need to generate an SSH key for the Jenkins user, use sudo to run as the proper user.
sudo -u jenkins ssh-keygen
Enjoy!
The post Install Jenkins as a Service on CentOS 7 appeared first on Justin Silver.
]]>The post Install WSDL2Apex on OS X El Capitan appeared first on Justin Silver.
]]>The WSDL2Apex generates the Apex classes necessary to implement a SOAP callout from the Force.com platform using the WSDL for the service you are trying to implement. In 2014 it was split out of the Force.com IDE codebase and was made open source , available on it’s own as an open source project.
This means that you can clone the GitHub project, build the JAR, and then use it to consume a WSDL and generate your Apex classes. There is one caveat for OS X El Capitan (and Yosemite as well) in that the operating system ships with Java 1.8, however WSDL2Apex requires Java 1.7 or earlier. If you try to run the build using a later version of Java, you will get 12-15 test errors (I got 12, other people reported 15).
Results : Failed tests: testAsyncFalse(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test 8 doesn't match expected:<...rmationByAirportCode[Response_element {(..) testNewClassNames(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): testNewClassNames doesn't match expected:<... }(..) testNoOperation(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test noOperation failed expected:<... public class Echo[Date_element {(..) testExchange(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test testExchange failed expected:<...{(..) testAmazonGood(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test testAmazonGood failed expected:<... {(..) testBigFile(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test testBigFile failed expected:<... {(..) testNamespaceDependencies(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test testNamespaceDependencies failed expected:<... {(..) testTwoNamespaces(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): testTwoNamespaces a doesn't match, Async class expected:<...mple.com/stockquote.[wsdl', 'exampleComStockquoteWsdl', 'http://example.com/stockquote.xsd', 'exampleComStockquoteXsd]'};(..) testSqlMutations(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test sqlMutations failed expected:<...lic class getMutants[CompressedResponse_element {(..) testMultipleNamespace(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): Test testMultipleNamespace failed expected:<... public class Echo[Date_element {(..) testLargeFile(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): testLargeFile a doesn't match expected:<...m/spectrum/services/[EOLS_PSAPLookupUS', 'wwwPbComSpectrumServicesEolsPsaplo', 'http://spectrum.pb.com/', 'spectrumPbCom', 'http://www.mapinfo.com/midev/service/geometries/v1', 'wwwMapinfoComMidevServiceGeometries', 'http://www.mapinfo.com/midev/service/units/v1', 'wwwMapinfoComMidevServiceUnitsV1', 'http://www.pb.com/spectrum/services/', 'wwwPbComSpectrumServic]es'};(..) testSimple(com.salesforce.ide.wsdl2apex.core.WSDL2ApexTest): testSimple doesn't match expected:<...rmationByAirportCode[Response_element {(..) Tests run: 47, Failures: 12, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.230 s [INFO] Finished at: 2015-11-23T20:30:10-08:00 [INFO] Final Memory: 8M/245M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project WSDL2Apex: There are test failures.
We’ll use Homebrew to install git (to fetch the project), Apache Maven (to build the project), and Java 1.6 from Apple to meet the version requirements.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install maven git
mkdir ~/SalesforceDev && cd ~/SalesforceDev git clone https://github.com/forcedotcom/WSDL2Apex cd WSDL2Apex
Visit the Apple support site to download and install Java 1.6 for OS X. It will be installed to your /Library/Java/JavaVirtualMachines/1.6.0.jdk/
directory.
We need to set the JAVA_HOME
directory to point to the 1.6 JDK so that Maven will use it for the build. To do this just set it before the actual mvn
execution. If you have Java 1.7 on your machine, feel free to substitute it for 1.6 – just check your JavaVirtualMachines
directory to see what’s available.
JAVA_HOME=/Library/Java/JavaVirtualMachines/j1.6.0.jdk/Contents/Home/ \ mvn install package
Bask in the glory that are your newly generated Apex SOAP classes.
The post Install WSDL2Apex on OS X El Capitan appeared first on Justin Silver.
]]>The post Install Jenkins on CentOS as a Service appeared first on Justin Silver.
]]>Updated post: Yum Install Jenkins as a Service on CentOS 7. You probably want to do it this way, it’s much easier. Just saying.
This guide describes how to install Jenkins on your CentOS server as an init.d
service. Jenkins is a great continuous integration server that can do a lot of cool automation, but I won’t go into all of those details here. If you don’t have Java or ANT
, you should install them before getting started – I am usingĀ java-1.7.0-openjdk.x86_64
but choose the appropriate JVM
for your server, either the OpenJDK
or Oracle JVM
is required.
yum -y install java-1.7.0-openjdk.x86_64 ant
Now on to the actual setup. All of the uppercase variables in the text below can be set in the /etc/sysconfig/jenkins
file. There are defaults for all values, so only create this file if you want to override them for your own environment. First let’s create the JENKINS_USER
.
groupadd jenkins useradd -g jenkins jenkins
Next create your JENKINS_HOME
and install Jenkins by downloading the latest version of the jenkins.war
.
sudo mkdir -p /usr/local/jenkins cd /usr/local/jenkins wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
Now create the scripts to start and stop the process, called /usr/local/start-jenkins.sh
and /usr/local/stop-jenkins.sh
respectively. Both of these files should be in the JENKINS_HOME
.
/usr/local/jenkins/start-jenkins.sh
#!/bin/bash # import sysconfig settings and set defaults [ -f /etc/sysconfig/jenkins ] && . /etc/sysconfig/jenkins [ "${JENKINS_HOME}" == "" ] && JENKINS_HOME=/usr/local/jenkins [ "${JENKINS_LOG}" == "" ] && JENKINS_LOG=/home/jenkins/jenkins.log [ "${JENKINS_JAVA}" == "" ] && JENKINS_JAVA=/usr/bin/java [ "${JENKINS_JAVAOPTS}" == "" ] && JENKINS_JAVAOPTS="" [ "${JENKINS_IP}" == "" ] && JENKINS_IP=0.0.0.0 [ "${JENKINS_PORT}" == "" ] && JENKINS_PORT=8080 [ "${JENKINS_ARGS}" == "" ] && JENKINS_ARGS="" JENKINS_WAR=${JENKINS_HOME}/jenkins.war # check for config errors JENKINS_ERRORS=() [ ! -f ${JENKINS_WAR} ] && JENKINS_ERRORS[${#JENKINS_ERRORS[*]}]="JENKINS_HOME : The jenkins.war could not be found at ${JENKINS_HOME}/jenkins.war" [ ! -f $JENKINS_JAVA ] && JENKINS_ERRORS[${#JENKINS_ERRORS[*]}]="JENKINS_JAVA : The java executable could not be found at $JENKINS_JAVA" # display errors if there are any, otherwise start the process if [ ${#JENKINS_ERRORS[*]} != '0' ] then echo "CONFIGURATION ERROR:" echo " The following errors occurred when starting Jenkins." echo " Please set the appropriate values at /etc/sysconfig/jenkins" echo "" for (( i=0; i<${#JENKINS_ERRORS[*]}; i++ )) do echo "${JENKINS_ERRORS[${i}]}" done echo "" exit 1 else echo "starting service" echo "nohup nice $JENKINS_JAVA $JENKINS_JAVAOPTS -jar $JENKINS_WAR --httpListenAddress=$JENKINS_IP --httpPort=$JENKINS_PORT $> $JENKINS_LOG 2>&1 &" nohup nice $JENKINS_JAVA $JENKINS_JAVAOPTS -jar $JENKINS_WAR --httpListenAddress=$JENKINS_IP --httpPort=$JENKINS_PORT $> $JENKINS_LOG 2>&1 & fi
/usr/local/jenkins/stop-jenkins.sh
#!/bin/bash kill `ps -ef | grep [j]enkins.war | awk '{ print $2 }'`
Now create a script called /etc/init.d/jenkins
to allow the server to be started and stopped as a service.
/etc/init.d/jenkins
#! /bin/bash # chkconfig: 2345 90 10 # description: Jenkins Continuous Integration server # processname: /usr/local/jenkins/jenkins.war # Source function library. . /etc/rc.d/init.d/functions # Get network sysconfig. . /etc/sysconfig/network # Check that networking is up, otherwise we can't start [ "${NETWORKING}" = "no" ] && exit 0 # Get the Jenkins sysconfig [ -f /etc/sysconfig/jenkins ] && . /etc/sysconfig/jenkins [ "${JENKINS_HOME}" = "" ] && JENKINS_HOME=/usr/local/jenkins [ "${JENKINS_USER}" == "" ] && JENKINS_USER=jenkins startup=${JENKINS_HOME}/start-jenkins.sh shutdown=${JENKINS_HOME}/stop-jenkins.sh export JAVA_HOME=/usr/local/java/ start(){ echo -n $"Starting Jenkins service: " pid=`ps -ef | grep [j]enkins.war | wc -l` if [ $pid -gt 0 ]; then echo "Jenkins is already running" exit 1 fi su - $JENKINS_USER -c $startup RETVAL=$? [ $RETVAL == 0 ] && echo "Jenkins was started successfully." || echo "There was an error starting Jenkins." } stop(){ action $"Stopping Jenkins service: " pid=`ps -ef | grep [j]enkins.war | wc -l` if [ ! $pid -gt 0 ]; then echo "Jenkins is not running" exit 1 fi su - $JENKINS_USER -c $shutdown RETVAL=$? [ $RETVAL == 0 ] && echo "Jenkins was stopped successfully." || echo "There was an error stopping Jenkins." } status(){ pid=`ps -ef | grep [j]enkins.war | wc -l` if [ $pid -gt 0 ]; then echo "Jenkins is running..." else echo "Jenkins is stopped..." fi } restart(){ stop sleep 5 start } # Call functions as determined by args. case "$1" in start) start;; stop) stop;; status) status;; restart) restart;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac exit 0
Make sure that the JENKINS_USER
is the owner of the JENKINS_HOME
directory and scripts, and that the scripts have executable flags set.
chown -R jenkins. /usr/local/jenkins chmod a+x /usr/local/jenkins/start-jenkins.sh chmod a+x /usr/local/jenkins/stop-jenkins.sh chmod a+x /etc/init.d/jenkins
You can then start, stop, restart, and check the status of the service via the following commands, or control if it is launched on boot using chkconfig
:
service jenkins status service jenkins start service jenkins restart service jenkins stop chkconfig jenkins on
The additional variables that can be set at /etc/sysconfig/jenkins
and their defaults are as follows:
# Jenkins system configuration JENKINS_HOME=/usr/local/jenkins JENKINS_USER=jenkins JENKINS_LOG=/home/jenkins/jenkins.log JENKINS_JAVA=/usr/bin/java JENKINS_JAVAOPTS="" JENKINS_IP=0.0.0.0 JENKINS_PORT=8080 JENKINS_ARGS=""
Since my development server already has Apache running on it, the easiest way to expose the application to the world was via a reverse proxy after I installed Jenkins. The VirtualHost
for this subdomain ends up looking like the following:
<VirtualHost *:80> ServerName jenkins.doublesharp.com DocumentRoot /var/www/html ProxyPass / http://localhost:8080/ nocanon ProxyPassReverse / http://localhost:8080/ ProxyRequests Off ProxyPreserveHost On <Proxy http://localhost:8080/*> Order deny,allow Allow from all </Proxy> # If using reverse proxy from SSL #Header edit Location ^http: https: </VirtualHost>
Complete the setup by restarting Apache.
service httpd restart
The post Install Jenkins on CentOS as a Service appeared first on Justin Silver.
]]>