In Jenkins display the directories from gitlab repo in build with parameters as a drop down - jenkins-pipeline

agent { label 'jenkins-slave' }
environment {
CRED_REPO_URL = 'gitcredentials.git'
SERVICES_REPO_URL = 'gitrepo'
ENV_NAME = 'dev_dev'
REGION = 'ap-south-1'
}
parameters {
choice name: 'ENV', choices: ['dev', 'qa'], description: 'Choose an env'
choice name: 'DIRS', choices: choiceArray, description: 'Choose a dir from branch'
gitParameter branchFilter: 'origin/(.*)',
tagFilter: '*',
defaultValue: 'main',
name: 'BRANCH',
type: 'BRANCHTAG',
quickFilterEnabled: 'true',
description: 'branch to execute',
useRepository: 'gitrepo'
}
}
facing some issue.so need to assist for this while select the branch in jenkins it has to shown that repo directories as a drop down.

Related

ARM Incremental deployment mode

Consider I have an Azure Function App with some app settings and some functions created via the following YAML task:
- task: AzureResourceManagerTemplateDeployment#3
displayName: 'deploy resources'
inputs:
azureResourceManagerConnection: azureResourceManagerConnection
subscriptionId:subscriptionId
resourceGroupName: rg
location:location
csmFile: template.bicep
csmParametersFile:parameters.json
deploymentMode: 'Incremental'
Let’s say I modified app settings.
If I run the above YAML task in Incremental deployment mode, does that recreate the Azure Function App with the modified app settings and functions or does it just update the app settings - Function app and existing functions stay the same?
Here is how my template.bicep looks like:
var appSettings = [
{
name: 'WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG'
value: 1
}
{
name: 'WEBSITE_ENABLE_SYNC_UPDATE_SITE'
value: 1
}
{
name: 'SCM_TOUCH_WEBCONFIG_AFTER_DEPLOYMENT'
value: 0
}
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: reference(resourceId(appInsightsResourceGroup, 'microsoft.insights/components/', appInsightsName), '2015-05-01').InstrumentationKey
}
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${listKeys(resourceId(storageAccountResourceGroup, 'Microsoft.Storage/storageAccounts', storageAccountName), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${listKeys(resourceId(storageAccountResourceGroup, 'Microsoft.Storage/storageAccounts', storageAccountName), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value}'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'dotnet'
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT'
value: maximumElasticWorkerCount
}
{
name: 'appConfigurationEndpoint'
value: appConfigurationEndpoint
}
{
name: 'membershipStorageAccountName'
value: '#Microsoft.KeyVault(SecretUri=${reference(membershipStorageAccountName, '2019-09-01').secretUriWithVersion})'
}
{
name: 'membershipContainerName'
value: '#Microsoft.KeyVault(SecretUri=${reference(membershipContainerName, '2019-09-01').secretUriWithVersion})'
}
]
var stagingSettings = [
{
name: 'WEBSITE_CONTENTSHARE'
value: toLower('functionApp-staging')
}
{
name: 'AzureFunctionsJobHost__extensions__durableTask__hubName'
value: '${solutionAbbreviation}compute${environmentAbbreviationStaging}'
}
{
name: 'AzureWebJobs.StarterFunction.Disabled'
value: 1
}
]
var productionSettings = [
{
name: 'WEBSITE_CONTENTSHARE'
value: toLower('functionApp')
}
{
name: 'AzureFunctionsJobHost__extensions__durableTask__hubName'
value: '${solutionAbbreviation}compute${environmentAbbreviation}'
}
{
name: 'AzureWebJobs.StarterFunction.Disabled'
value: 0
}
]
module functionAppTemplate 'functionApp.bicep' = {
name: 'functionAppTemplater'
params: {
name: '${functionAppName}'
kind: functionAppKind
location: location
servicePlanName: servicePlanName
dataKeyVaultName: dataKeyVaultName
dataKeyVaultResourceGroup: dataKeyVaultResourceGroup
secretSettings: union(appSettings, productionSettings)
}
dependsOn: [
servicePlanTemplate
]
}
module functionAppSlotTemplate 'functionAppSlot.bicep' = {
name: 'functionAppSlotTemplate'
params: {
name: '${functionAppName}/staging'
kind: functionAppKind
location: location
servicePlanName: servicePlanName
dataKeyVaultName: dataKeyVaultName
dataKeyVaultResourceGroup: dataKeyVaultResourceGroup
secretSettings: union(appSettings, stagingSettings)
}
dependsOn: [
functionAppTemplate
]
}
functionapp.bicep
resource functionApp 'Microsoft.Web/sites#2018-02-01' = {
name: name
location: location
kind: kind
properties: {
serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
clientAffinityEnabled: false
httpsOnly: true
siteConfig: {
use32BitWorkerProcess : false
appSettings: secretSettings
}
}
identity: {
type: 'SystemAssigned'
}
}
functionAppSlot.bicep
resource functionAppSlot 'Microsoft.Web/sites/slots#2018-11-01' = {
name: name
kind: kind
location: location
properties: {
clientAffinityEnabled: true
enabled: true
httpsOnly: true
serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
siteConfig: {
use32BitWorkerProcess : false
appSettings: secretSettings
}
}
identity: {
type: 'SystemAssigned'
}
}
Your Function App will not be recreated. Only the state or values which does not match the desired state are changed.
This means, if you change a setting e.g. FUNCTIONS_EXTENSION_VERSION in the bicep file, it will be changed in the Function App settings.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/overview
Repeatable results: Repeatedly deploy your infrastructure throughout the development lifecycle and have confidence your resources are deployed in a consistent manner. Templates are idempotent, which means you can deploy the same template many times and get the same resource types in the same state. You can develop one template that represents the desired state, rather than developing lots of separate templates to represent updates.

Using Function in JenkinsFile Parameter Description

I am trying to add a function in JenkinsFile Declarative pipelines parameter's description but struggling to make it work.
Idea is to have a Jenkins Job specific for the environment. and would like to see the choice parameter to show environment name in the description of the variable.
My pipeline looks like this
def check_env = app_env(ENVS, env.JOB_NAME)
pipeline {
agent { label 'master' }
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '20'))
timestamps()
}
parameters{
string(name: 'myVariable', defaultValue: "/", description: 'Enter Path To App e.g / OR /dummy_path for ' {check_env} )
}
stages{
stage('Running App') {
agent {
docker {
image 'myApp:latest'
}
}
steps{
script{
sh label: 'App', script: "echo "App is running in ${check_env} "
}
}
}
}
}
}
I have tried multiple combinations for check_env e.g check_env, check_env(), ${check_env} function but none of them worked.
String Interpolation
I believe this is simply a String Interpolation issue. Notice my use of double quotes below
parameters{
string(name: 'myVariable', defaultValue: "/", description: "Enter Path To App e.g / OR /dummy_path for ${check_env}")
}
Your build page should then interpolate your variable
To test I simply set def check_env = 'live' since I do not have the code for your method

Batch file is not getting executed in jenkin pipeline

I am having jenkin Jenkins 2.289.1, at I am converting the existing job to the pipeline.
The same batch which is working in job but is not working in pipeline.
Even when the batch file does not exist, no error thrown but task ended as completed.
Any idea on the issue?
pipeline {
agent any
parameters {
choice(name: 'RELEASE', choices: ['860', '859', '858','857'], description: 'Pick something')
string(name: 'SrcTestSetNameToCopy', defaultValue: '', description: 'Source ALM test Set Name')
string(name: 'TestSetNameToBeCreated', defaultValue: '', description: 'Test Set Name to create')
choice(name: 'Platform', choices: ['ORACLE', 'MICROSFT', 'DB2ODBC'], description: 'Pick something')
string(name: 'BuildOverride', defaultValue: '', description: '4 dit build overwrite value')
choice(name: 'EnvnBuildType', choices: ['DEP', 'QAE'], description: 'Pick something')
booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')
}
stages {
stage('Create ALM Test Set') {
steps {
// bat "\"C:\\JenKin_Jobs\\Test.bat\""
// bat 'C:/JenKin_Jobs/Test1.bat'
// bat 'wmic computersystem get name'
//bat 'echo %PATH%'
echo 'selva'
echo "Current workspace is $WORKSPACE"
//bat returnStatus: true, script: 'C:\\JenKin_Jobs\\Test.bat'
bat script: 'C:\\JenKin_Jobs\\Test.bat'
}
}
}
}
pipeline {
agent any
stages {
stage('Hello') {
steps {
// below simple echo executed
echo 'Hello World'
//bat 'C:\\JenKin_Jobs\\NetUSeIDrive.bat'
bat 'cmd.exe "/c C:\\JenKin_Jobs\\NetUSeIDrive.bat" '
bat 'cmd.exe /c c:\\JenKin_Jobs\\SQAClnUp.bat "I:\\\\***\\\\SQA_CONFIG_FILES\\\\859 Stuff\\\\####\\\\P05\\\\P05B"'
}
}
}
}
The pipeline works in one set of box but not in another? IS there any config missing between the boxes. Both are usins same jenkin version

How can i pass variables from jenkins file to terraform

when i run terraform with local variables inside variable.tf everything work like a charm
i want to pass Jenkins parameters inside terraform variable.tf file so it will be dynamic from Jenkins
how can i achieve it?
pipeline {
agent any
options {
skipDefaultCheckout true
}
environment {
TF_VAR_datacenter="${DATA_CENTER}"
TF_VAR_cluster="${CLUSTER}"
TF_VAR_esxi="${ESXI}"
TF_VAR_datastore="${DATASTORE}"
TF_VAR_network="${NETWORK}"
TF_VAR_server_hostname="${SERVER_HOSTNAME}"
TF_VAR_server_mac="${SERVER_MAC}"
}
parameters {
string(name: 'DATA_CENTER', defaultValue: 'xxx', description: 'vcenter data center',)
string(name: 'CLUSTER', defaultValue: 'xxx', description: 'data center cluster',)
string(name: 'ESXI', defaultValue: 'xxx', description: 'esxi hostname',)
string(name: 'DATASTORE', defaultValue: 'xxx', description: 'data center datastore',)
string(name: 'NETWORK', defaultValue: 'xxx', description: 'data center network',)
string(name: 'SERVER_HOSTNAME', defaultValue: 'xxx', description: 'server hostname',)
string(name: 'SERVER_MAC', defaultValue: 'xxx', description: 'server mac',)
string(name: 'SERVER_IP', defaultValue: 'xxx', description: 'server ip',)
string(name: 'SERVER_NETMASK', defaultValue: 'xxx', description: 'server netmask',)
string(name: 'SERVER_GATEWAY', defaultValue: 'xxx', description: 'server gateway',)
string(name: 'COBBLER_PROFILE', defaultValue: 'xxx', description: 'cobbler profile',)
choice(name: 'BUILD_DESTROY', description: '', choices: ['build' , 'destroy'])
}
stages {
stage('OS PROVISION') {
steps {
dir("/root/terraform"){
sh """
export TF_VAR_datacenter=${DATA_CENTER}
export TF_VAR_cluster=${CLUSTER}
export TF_VAR_esxi=${ESXI}
export TF_VAR_datastore=${DATASTORE}
export TF_VAR_network=${NETWORK}
export TF_VAR_server_hostname=${SERVER_HOSTNAME}
export TF_VAR_server_mac=${SERVER_MAC}
terraform init
terraform apply -auto-approve
"""
}
}
}
}
post {
always {
echo 'This will always run'
}
}
}
I prefer use this format:
terraform apply \
-var 'vpc_id=$(AWS_VPC_ID)' \
-var 'subnet_id=$(AWS_SUBNET_ID)' \
-var 'aws_region=$(AWS_REGION)' \
-var 'ami_id=$(AMI_ID)'\
-var 'instance_type=$(AWS_EC2_TYPE)' \
-var 'key_pair=$(KEY_PAIR_NAME)' \
-var 'tags={ "Owner":"$(OWNER)", "Service":"$(SERVICE)", "Terraform":"true", "Env":"$(ENV)" }'
Your question needs a bit more clarity, but I am going to make a few educated guesses.
with local variables inside variable.tf
Do you mean locals {, or what exactly do you mean by local variables?
pass Jenkins parameters inside terraform variable.tf file
This isn't the right file to 'pass parameters'. *.tf files are for declaring variables.
You are probably looking at *.tfvars files.
You have 3 options with *.tfvars files:
a file named exactly terraform.tfvars
a file named <anything>.auto.tfvars
a file named <anything>.tfvars which you reference using the -var-file CLI parameter.
The format of *.tfvars files is simply:
var1_name = var1_value
You can (must) use the usual HCL markup fo trings, lists, maps, ...

How to declare variables in jenkinsfile

I am trying to fetch the repo details from a variable in the jenkinsfile. Can someone guide on why this is not working?
parameters {
string(defaultValue: "develop", description: 'enter the branch name to use', name: 'branch')
string(defaultValue: "repo1", description: 'enter the repo name to use', name: 'reponame')
}
stage('Branch Update'){
dir("${param.reponame}"){
bat """ echo branch is ${params.branch}"""
}
}
When i run the above, I get the following error message:
groovy.lang.MissingPropertyException: No such property: param for class: groovy.lang.Binding
[Pipeline] }
You have a typo. Instead of param.reponame it should be params.reponame.

Resources