I am trying to deploy the build to gh pages from travis ci. But, I am not able to access the variables from within the git commands, otherwise the variables are accessible when simply trying to echo them.
jobs:
include:
- stage: "lint"
name: "Check for code smell"
script: yarn lint
- stage: "deploy"
name: "Deploy to GH Pages"
script:
- git config --global user.name ${Name}
- git config --global user.email ${Email}
- git remote rm origin
- git remote add origin https://linux-nerd:${GITHUB_TOKEN}#${GH_REF}
- yarn run deploy
- echo ${Email}
- echo $Email
- echo https://linux-nerd:${GITHUB_TOKEN}#${GH_REF}
The last three echos are printing correctly, but the git commands do not take the correct values.
What am I missing?
this is how I configure git user and email:
git config --global user.name "username"
git config --global user.email "email"
Please not the use of "" above
thats what u are missing in your file
Related
I've setup a bitbucket pipeline successfully. The issue I'm having is how to run my database migrations after deployment has been completed. I'm using git-ftp. Specifically, I wish to cd into my directory via FTP, and run my migrations, like php vendor/bin migrate
image: wagnerstephan/bitbucket-git-ftp:latest
pipelines:
custom:
init:
- step:
caches:
- node
script:
- git reset --hard
- git ftp init -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST
deploy:
- step:
caches:
- node
script:
- git reset --hard
- git ftp push -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST --all
branches:
master:
- step:
name: Deploy production
deployment: production
caches:
- node
script:
- git reset --hard
- git ftp push -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST
- step:
name: 'Migrations'
image: php:7.4-fpm
script:
- # cd into my FTP server folder
- # run migrations
- php /public_html/home.php
I've searched around, but cannot seem to find a tutorial on this
I would like to edit the gitlab cicd variables thru my pipeline script.
Flow:
Submit merge request
CI pipeline retrieve the version number (variable stored in the CICD project setting (refer to pic although the variable version is not included)
version+1 and set back into the CICD project setting
git tag the file based on version number
the file i want to git tag is a bash script file and I am using Linuxx docker image. please advise
current script
variables:
PROFILE_NAME: default
default:
image: docker-image
stages:
- tagging
Tag:
stage: tag
script:
- yum install git -y
- git --version
- git remote set-url --push origin ${CI_SERVER_PROTOCOL}://${GITLAB_PERSONAL_ACCESS_TOKEN_NAME}:${GITLAB_PERSONAL_ACCESS_TOKEN}#${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git
- export "VERSION=$(($VERSION +1 ))" > $INC_VERSION
- echo 'after version:' $VERSION
- echo 'after increment version:' $INC_VERSION
- git push origin --tags
only:
refs:
- merge_requests
variables:
- ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^dev/ || $CI_COMMIT_BRANCH =~ /^dev/ || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^release-/ || $CI_COMMIT_BRANCH =~ /^release-/)
except:
variables:
- ($CI_COMMIT_BEFORE_SHA == '0000000000000000000000000000000000000000' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME !~ /^./)
Wtth help of below article i've setup SSH keys for bitbucket so i can use it in pipelines
https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/
When tested on terminal window by entering following command it works fine:
$ ssh -T git#bitbucket.org
but when i run my pipelines it fails
Added public key under my bitbucket profile
My Pipeline:
image:
name: abhisheksaxena7/salesforcedockerimg
pipelines:
branches:
feature/**:
- step:
script:
- ant -buildfile build/build.xml deployEmptyCheckOnly -Dsfdc.username=$SFDC_USERNAME -Dsfdc.password=$SFDC_PASS$SFDC_TOKEN -Dsfdc.serverurl=https://$SFDC_SERVERURL
# master:
# - step:
# script:
# - ant -buildfile build/build.xml deployCode -Dsfdc.username=$SFDC_USERNAME -Dsfdc.password=$SFDC_PASS$SFDC_TOKEN -Dsfdc.serverurl=https://$SFDC_SERVERURL
Admin-Changes:
- step:
script:
- echo my_known_hosts
# Set up SSH key; follow instructions at https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Bitbucket+Pipelines
- (mkdir -p ~/.ssh ; cat my_known_hosts >> ~/.ssh/known_hosts; umask 077 ; echo $SSH_KEY | base64 --decode -i > ~/.ssh/id_rsa)
# Read update_to_trigger_pipelines.txt into commitmsg variable
- commitmsg="$(<update_to_trigger_pipelines.txt)"
# Set up repo and checkout master
- echo git#bitbucket.org:$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG.git
- git remote set-url origin git#bitbucket.org:$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG.git
- git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
- git fetch
- git checkout master
# Get metadata from server
- ant -buildfile build/build.xml getCode -Dsfdc.username=$SFDC_USERNAME -Dsfdc.password=$SFDC_PASS$SFDC_TOKEN -Dsfdc.serverurl=https://$SFDC_SERVERURL
# Commit any changes to master
- git add force-app/main/default/*
- git config user.name "$GIT_USERNAME"
- git config user.email "$GIT_EMAIL"
- if [[ -n $(git status -s) ]] ; then filelist=`git status -s` ; git commit -a -m "$commitmsg" -m "$filelist" ; git push origin master:master ; else echo "No changes detected"; fi
I was adding my local server ssh key to my profile instead repository SSH KEY, so i had to get repository pipelines SSH Keys and add it to my profile.
I am running this .yml file
kind: pipeline
type: docker
name: default
steps:
- name: test
image: ubuntu
commands:
- apt-get update
- apt-get install git -y
- ./build.sh bin
first, two commands are running correctly but in the last command it fails and the drone doesn't give me a message
![drone messages get while testing][1]
This fails after echo if1
PROJECT_PATH=$PWD
RUN=$1
ENVIRONMENT=${ENVIRONMENT:="local"}
if [ "$ENVIRONMENT" == "local" ]; then
echo if1
GIT_AUTHOR="$(git config --global --get user.name)"
GIT_AUTHOR_EMAIL="$(git config --global --get user.email)"
GIT_VERSION="$(git describe --tags --always --dirty)"
VERSION=$GIT_VERSION
echo endif
else
echo else1
DRONE_COMMIT_SHORT=${DRONE_COMMIT:0:8}
VERSION=${DRONE_TAG:=$DRONE_COMMIT_SHORT}
echo endelse
``
[1]: https://i.stack.imgur.com/ChrUo.png
You need shebang
#!/usr/bin/env bash
Your bash
I have the following pipelines file:
node('git') {
stage('Set Git Config') {
sh 'git config --global user.email "jenkins#test.com"'
sh 'git config --global user.name "jenkins"'
sh 'git config --global credential.helper cache'
sh "git config --global credential.helper 'cache --timeout=3600'"
}
stage('Set Git Credentials') {
git credentialsId: 'gitlab1', url: '${GITLAB1_REPO}'
git credentialsId: 'gitlab2', url: '${GITLAB2_REPO}'
}
stage('Synchronize with Gitlab2'){
sh 'git clone --bare ${GITLAB1_REPO} tfs'
dir("tfs") {
//add a remote repository
sh 'git remote add --mirror=fetch second ${GITLAB2_REPO}'
// update the local copy from the first repository
sh 'git fetch origin --tags'
// update the local copy with the second repository
sh 'git fetch second --tags'
// sync back the second repository
sh 'git push second --all'
sh 'git push second --tags'
}
}
}
Stage 1 and Stage 2 work perfectly. Stage 3 fails with permission denied.
I find this strange because on Stage 2, I can already see what the last commit was so it indicates that the credentials do work. Why aren't they working on stage 3?
This is the error I am seeing:
git clone --bare git#bitbucket.test/test.git tfs Cloning
into bare repository 'tfs'... Permission denied (publickey). fatal:
Could not read from remote repository.
While in stage 2, I see:
git config core.sparsecheckout # timeout=10
git checkout -f 30f1a7d1b77ef64e1cd44eab11a6ef4541c23b43
git branch -a -v --no-abbrev # timeout=10
git branch -D master # timeout=10
git checkout -b master 30f1a7d1b77ef64e1cd44eab11a6ef4541c23b43 Commit message: "test commit"
Stage 1 - you add some settings in shell to local git
Stage 2 - you point to actual credentials to be used and use a Jenkins plugin - which would just work
Satge 3 - back to shell, no credentials provided from jenkins, so the context is slave/local jenkins user.
Solution would be to use withCredentials for username and password or sshagent(credentials...) for private key
// credentialsId here is the credentials you have set up in Jenkins for pushing
// to that repository using username and password.
withCredentials([usernamePassword(credentialsId: 'git-pass-credentials-ID', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh("git tag -a some_tag -m 'Jenkins'")
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}#<REPO> --tags')
}
// For SSH private key authentication, try the sshagent step from the SSH Agent plugin.
sshagent (credentials: ['git-ssh-credentials-ID']) {
sh("git tag -a some_tag -m 'Jenkins'")
sh('git push <REPO> --tags')
}