Fastlane – Badge for iOS

The Badge plugin for Fastlane allows you to offer version numbers, release type, etc.

On the MacOS collector, install the dependencies:

brew install librsvg
brew install imagemagick
brew install graphicsmagick

Add a line to the project Gemfile:

gem 'fastlane-plugin-badge'

Add a block related to the badge to Fastfile and add the version number via a variable.

jenkinsVersionNumber = ENV["APP_VERSION"]

...

lane :adhoc do
  add_badge(
    alpha: true,
    dark: true,
    shield: "Version-#{jenkinsVersionNumber}-orange",
    grayscale: true
  )

...
end

 

Kubernetes – Shared folder between two containers in pod

An example of creating a common directory for two containers in one pod.

apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data

CloudFormation – Put credentials from S3 in EC2 Instance

An example of CloudFormation for transfer to the inside of EC2 instanceACCESS_KEY” and “SECRET_KEY” directly from the IAM to access the S3 Bucket using AWS-Cli.

AWSTemplateFormatVersion: "2010-09-09"
Description: 'Auto create VPC with instance'

########################################### BLOCK WITH ENVIRONMENTS ###########################################
Parameters:

  ProjectName:
    Type: String
    Default: ArtemPool
    Description: Name of project.

  SSHKeyName:
    Type: String
    Default: artem
    Description: Name of SSH key.

  Image:
    Type: String
    Default: ami-0ff8a91507f77f867
    Description: Image for instance (Default - Amazon Linux, if you changes it, you must install AWS-Cli manualy)
    ConstraintDescription: (ami-0ff8a91507f77f867 - Amazon Linux)

  Region:
    Type: String
    Default: us-east-1b
    Description: Region (Default - U.S. Virginia)

####################################### BLOCK WITH IAM FOR ACCESS TO S3  ######################################

Resources:
  myaccesskey:
    Type: AWS::IAM::AccessKey
    Properties:
      UserName: artem-s3

########################################## BLOCK WITH EC2 INSTANCES  ##########################################

  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref Image
      InstanceType: t2.micro
      KeyName: !Ref SSHKeyName
      BlockDeviceMappings:
        -
          DeviceName: /dev/sdm
          Ebs:
            VolumeType: io1
            Iops: 200
            DeleteOnTermination: true
            VolumeSize: 20
      UserData:
        Fn::Base64: !Sub ACCESS_KEY=${myaccesskey}&&SECRET_KEY=${myaccesskey.SecretAccessKey}

Outputs: 
  AccessKeyformyaccesskey:
    Value:
      !Ref myaccesskey
  SecretKeyformyaccesskey:
    Value: !GetAtt myaccesskey.SecretAccessKey

###############################################################################################################

Jenkins – DSL Pipeline creating by Seed Job

In the repository where the future groovy files will be stored, create a directory called “utilities” and create the file “GithubPipeline.groovy” in it with the following contents:

package utilities

import javaposse.jobdsl.dsl.DslFactory

class GithubPipeline {

    String name
    String description
    String displayName
    String branchesName
    String urlRepo
    String credentialsId


	void build(DslFactory dslFactory) {
	    def job = dslFactory.pipelineJob(name) {
	        description(description)
	        displayName(displayName)
			definition {
		        cpsScm {
		            scm {
		                git {
		                    branches(branchesName)
		                    remote {
		                        url(urlRepo)
                        		credentials(credentialsId)
		                    }
		                }
		                scriptPath('Jenkinsfile')
		                lightweight(true)
		            }
		        }
		    }
		    parameters {
		        choiceParam ('Environment', ['staging', 'production', 'staging-without-cache'], 'Please choice env to build')
		    }
		    triggers {
		        bitbucketPush()
		    }
		}
	}
}

Now, to create an Item, it is enough to create a file with the groovy extension in the root of the repository, so that it can be processed by Seed Job.

Continue reading “Jenkins – DSL Pipeline creating by Seed Job”

Jenkins – Example DSL Pipeline

Sample Pipeline configuration file for a DSL module. This is a parameterized build. Jenkinsfile is located at the root of the repository.

pipelineJob('DSL_Pipeline') {
    displayName('DSL Pipeline')
    definition {
        cpsScm {
            scm {
                git {
                    branches('*/dsl-test')
                    remote {
                        url ('[email protected]:artem/devops.git')
                        credentials ('artem-github')
                    }
                }
                scriptPath ('Jenkinsfile')
                lightweight (true)
            }
        }
    }
    parameters {
        choiceParam('Environment', ['staging', 'production', 'staging-without-cache'], 'Please choice env to build')
    }
    triggers {
        bitbucketPush()
    }
}

Jenkins – DSL Multibranch Pipeline Creating by Seed Job

In the repository where the future groovy files will be stored, create a directory called “utilities” and create the file “BitbucketMultibranch.groovy” in it with the following contents:

package utilities

import javaposse.jobdsl.dsl.DslFactory

class BitbucketMultibranch {

    String name
    String description
    String displayName
    String serverUrl
    String repoOwner
    String repository
    String credentialsId
    String includeBranches
    String excludeBranches

	void build(DslFactory dslFactory) {
	    def job = dslFactory.multibranchPipelineJob(name) {
	        description(description)
	        displayName(displayName)
	        branchSources {
	            branchSource {
	                source {
	                    bitbucket {
	                        serverUrl(serverUrl)
	                        repoOwner(repoOwner)
	                        repository(repository)
	                        credentialsId(credentialsId)
	                        traits {
	                            headWildcardFilter {
	                                excludes(excludeBranches)
	                                includes(includeBranches)
	                            }
	                        }
	                    }
	                }
	            }
	        }
	        configure {
	          	def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
	          	traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
	            	strategyId(3) // detect all branches
	          	}
	        }
        	factory {
	            workflowBranchProjectFactory {
	                scriptPath('.jenkins/Jenkinsfile')
	            }
	        }
	        orphanedItemStrategy {
	            discardOldItems {
	                numToKeep(15)
	            }
	        }
	    }
	}
}

Now, to create an Item, it is enough to create a file with the groovy extension in the root of the repository, so that it can be processed by Seed Job.

Continue reading “Jenkins – DSL Multibranch Pipeline Creating by Seed Job”

Jenkins – Example DSL Multibranch Pipeline

Example Multibranch Pipeline configuration file for a DSL module, with a custom Bitbucket server. Which will include branches: “develop“, “staging” and “master“. Will store the last 15 builds. And look for Jenkins file along the path: “.jenkins/Jenkinsfile

  • Repository name: artem-dsl
  • Owner (project name): dev
  • Loans of Jenkins access to Bitbucket: svn-bibucket
multibranchPipelineJob('artem-dsl') {
    displayName('Artem-DSL')
    description('DSL test')
    branchSources {
        branchSource {
            source {
                bitbucket {
                    serverUrl('https://git.artem.services')
                    repoOwner('dev')
                    repository('artem-dsl')
                    credentialsId('svc-bitbucket')
                    traits {
                        headWildcardFilter {
                            excludes('')
                            includes('develop staging master')
                        }
                    }
                }
            }
        }
    }
    configure {
      def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
      traits &amp;lt;&amp;lt; 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
          strategyId(3) // detect all branches
      }
    }
    factory {
        workflowBranchProjectFactory {
            scriptPath('.jenkins/Jenkinsfile')
        }
    }
    orphanedItemStrategy {
        discardOldItems {
            numToKeep(15)
        }
    }
}

Jenkins – Forcibly set the build number

In order to force the build number, go to the user’s home directory “jenkins” -> “jobs” -> “Project_name” -> “Branch_name” and open the file “nextBuildNumber“. And indicate in it the number of the next assembly.

After that, it is necessary for Jenkins to re-read the data from the disk, for this we go to the settings and find the item “Reload configuration from disk