@@ -108,6 +108,7 @@ class BitbucketScm extends Scm {
108108 * @param {String } options.oauthClientSecret OAuth Client Secret provided by Bitbucket application
109109 * @param {String } [options.username=sd-buildbot] Bitbucket username for checkout
110110 * @param {String } [options.email=dev-null@screwdriver.cd] Bitbucket user email for checkout
111+ * @param {Object } [options.readOnly={}] Read-only SCM instance config with: enabled, username, accessToken, cloneType
111112 * @param {Boolean } [options.https=false] Is the Screwdriver API running over HTTPS
112113 * @param {Object } [options.fusebox={}] Circuit Breaker configuration
113114 * @return {BitbucketScm }
@@ -118,6 +119,12 @@ class BitbucketScm extends Scm {
118119 this . config = joi . attempt ( config , joi . object ( ) . keys ( {
119120 username : joi . string ( ) . optional ( ) . default ( 'sd-buildbot' ) ,
120121 email : joi . string ( ) . optional ( ) . default ( 'dev-null@screwdriver.cd' ) ,
122+ readOnly : joi . object ( ) . keys ( {
123+ enabled : joi . boolean ( ) . optional ( ) ,
124+ username : joi . string ( ) . optional ( ) ,
125+ accessToken : joi . string ( ) . optional ( ) ,
126+ cloneType : joi . string ( ) . valid ( 'https' , 'ssh' ) . optional ( ) . default ( 'https' )
127+ } ) . optional ( ) . default ( { } ) ,
121128 https : joi . boolean ( ) . optional ( ) . default ( false ) ,
122129 oauthClientId : joi . string ( ) . required ( ) ,
123130 oauthClientSecret : joi . string ( ) . required ( ) ,
@@ -794,19 +801,31 @@ class BitbucketScm extends Scm {
794801
795802 // Git clone
796803 command . push ( `echo 'Cloning ${ checkoutUrl } , on branch ${ branch } '` ) ;
797- command . push ( 'if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; ' +
798- `then export SCM_URL=${ sshCheckoutUrl } ; ` +
799- 'elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; ' +
800- `then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@${ checkoutUrl } ; ` +
801- `else export SCM_URL=https://${ checkoutUrl } ; fi`
802- ) ;
804+
805+ // Use read-only clone type
806+ if ( hoek . reach ( this . config , 'readOnly.enabled' ) ) {
807+ if ( hoek . reach ( this . config , 'readOnly.cloneType' ) === 'ssh' ) {
808+ command . push ( `export SCM_URL=${ sshCheckoutUrl } ` ) ;
809+ } else {
810+ command . push ( 'if [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; ' +
811+ `then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@${ checkoutUrl } ; ` +
812+ `else export SCM_URL=https://${ checkoutUrl } ; fi` ) ;
813+ }
814+ } else {
815+ command . push ( 'if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; ' +
816+ `then export SCM_URL=${ sshCheckoutUrl } ; ` +
817+ 'elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; ' +
818+ `then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@${ checkoutUrl } ; ` +
819+ `else export SCM_URL=https://${ checkoutUrl } ; fi` ) ;
820+ }
803821 command . push ( 'if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; '
804822 + `then ${ gitWrapper } `
805823 + `"git clone --recursive --quiet --progress --branch '${ branch } ' `
806824 + '$SCM_URL $SD_SOURCE_DIR"; '
807825 + `else ${ gitWrapper } `
808826 + '"git clone --depth=50 --no-single-branch --recursive --quiet --progress '
809827 + `--branch '${ branch } ' $SCM_URL $SD_SOURCE_DIR"; fi` ) ;
828+
810829 // Reset to Sha
811830 command . push ( `echo 'Reset to SHA ${ checkoutRef } '` ) ;
812831 command . push ( `${ gitWrapper } "git reset --hard '${ checkoutRef } '"` ) ;
0 commit comments